• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mapbox_vector_tile.decode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mapbox_vector_tile.decode函数的典型用法代码示例。如果您正苦于以下问题:Python decode函数的具体用法?Python decode怎么用?Python decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了decode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_points_pbf

    def test_points_pbf(self):
        '''
        Create 3 points (2 on west, 1 on east hemisphere) and retrieve as pbf.
        2 points should be returned in western hemisphere and 1 on eastern at zoom level 1
        (clip on)
        '''
        
        self.defineGeometry('POINT')

        point_sf = Point(-122.42, 37.78)
        point_berlin = Point(13.41, 52.52)
        point_lima = Point(-77.03, 12.04)

        self.insertTestRow(point_sf.wkt, 'San Francisco')
        self.insertTestRow(point_berlin.wkt, 'Berlin')
        self.insertTestRow(point_lima.wkt, 'Lima')

        ########
        # northwest quadrant should return San Francisco and Lima

        tile_mimetype, tile_content = utils.request(self.config_file_content, "vectile_test", "pbf", 0, 0, 1)
        pbf_result = mapbox_vector_tile.decode(tile_content)


        self.assertTrue(tile_mimetype.endswith('/x-protobuf'))
        self.assertIn('vectile_test', pbf_result)
        layer_result = pbf_result['vectile_test']
        self.assertEqual(len(layer_result['features']), 2)

        extent = tile_bounds_mercator(0, 0, 1)

        cities = []

        # Make sure that the right cities have been returned and that the geometries match

        for feature in layer_result['features']:
            if feature['properties']['name'] == 'San Francisco':
                cities.append(feature['properties']['name'])
                self.assertTrue(point_sf.almost_equals(decoded_pbf_asshape(feature, extent), decimal=1))

            elif feature['properties']['name'] == 'Lima':
                cities.append(feature['properties']['name'])
                self.assertTrue(point_lima.almost_equals(decoded_pbf_asshape(feature, extent), decimal=1))

        self.assertTrue('San Francisco' in cities)
        self.assertTrue('Lima' in cities)

        ##########
        # northeast quadrant should return Berlin

        tile_mimetype, tile_content = utils.request(self.config_file_content, "vectile_test", "pbf", 0, 1, 1)
        pbf_result = mapbox_vector_tile.decode(tile_content)

        self.assertTrue(tile_mimetype.endswith('/x-protobuf'))
        self.assertIn('vectile_test', pbf_result)
        layer_result = pbf_result['vectile_test']
        self.assertEqual(len(layer_result['features']), 1)
        self.assertTrue('Berlin' in layer_result['features'][0]['properties']['name'])
开发者ID:TileStache,项目名称:TileStache,代码行数:58,代码来源:vectiles_tests.py


示例2: test_bowtie_self_crossing

    def test_bowtie_self_crossing(self):
        from mapbox_vector_tile import encode
        from mapbox_vector_tile.encoder import on_invalid_geometry_make_valid
        import shapely.geometry
        import shapely.wkt
        bowtie = ('POLYGON ((0 0, 2 2, 2 0, 0 2, 0 0))')
        shape = shapely.wkt.loads(bowtie)
        self.assertFalse(shape.is_valid)
        feature = dict(geometry=shape, properties={})
        source = dict(name='layername', features=[feature])
        pbf = encode(source,
                     on_invalid_geometry=on_invalid_geometry_make_valid)
        result = decode(pbf)
        self.assertEqual(1, len(result['layername']['features']))
        valid_geometries = result['layername']['features'][0]['geometry']
        multipolygon = shapely.geometry.shape(valid_geometries)
        self.assertEqual(multipolygon.geom_type, 'MultiPolygon')
        self.assertTrue(multipolygon.is_valid)

        total_area = 0
        for p in multipolygon.geoms:
            self.assertEqual(p.geom_type, 'Polygon')
            self.assertTrue(p.is_valid)
            self.assertGreater(p.area, 0)
            total_area += p.area
        self.assertEquals(2, total_area)
开发者ID:ptpt,项目名称:mapbox-vector-tile,代码行数:26,代码来源:test_encoder.py


示例3: test_make_valid_can_return_multipolygon

    def test_make_valid_can_return_multipolygon(self):
        from mapbox_vector_tile import encode
        from mapbox_vector_tile.encoder import on_invalid_geometry_make_valid
        import shapely.wkt
        import os.path

        test_dir = os.path.dirname(os.path.realpath(__file__))
        file_name = 'error_nested_multipolygon.wkt'

        with open(os.path.join(test_dir, file_name)) as fh:
            shape = wkt.loads(fh.read())

        features = [dict(geometry=shape, properties={})]
        pbf = encode({'name': 'foo', 'features': features},
                     quantize_bounds=(-10018754.1713946, 11271098.44281893,
                                      -8766409.899970269, 12523442.714243261),
                     on_invalid_geometry=on_invalid_geometry_make_valid)
        result = decode(pbf)
        features = result['foo']['features']
        self.assertEqual(1, len(features))
        geom = features[0]['geometry']
        self.assertEquals(geom['type'], 'MultiPolygon')
        multipolygon = shapely.geometry.shape(geom)
        self.assertTrue(multipolygon.is_valid)

        area = 0
        for p in multipolygon.geoms:
            self.assertTrue(p.is_valid)
            area += p.area
        self.assertEquals(4339852.5, area)
开发者ID:ptpt,项目名称:mapbox-vector-tile,代码行数:30,代码来源:test_encoder.py


示例4: assertRoundTrip

 def assertRoundTrip(self, input_geometry, expected_geometry, name=None,
                     properties=None, id=None, expected_len=1,
                     expected_properties=None):
     if input_geometry is None:
         input_geometry = self.feature_geometry
     if name is None:
         name = self.layer_name
     if properties is None:
         properties = self.feature_properties
     if expected_properties is None:
         expected_properties = properties
     source = [{
         "name": name,
         "features": [{
             "geometry": input_geometry,
             "properties": properties
         }]
     }]
     if id:
         source[0]['features'][0]['id'] = id
     encoded = encode(source)
     decoded = decode(encoded)
     self.assertIn(name, decoded)
     layer = decoded[name]
     features = layer['features']
     self.assertEqual(expected_len, len(features))
     self.assertEqual(features[0]['properties'], expected_properties)
     self.assertEqual(features[0]['geometry'], expected_geometry)
     if id:
         self.assertEqual(features[0]['id'], id)
开发者ID:rory,项目名称:mapbox-vector-tile,代码行数:30,代码来源:test_encoder.py


示例5: test_decoder

 def test_decoder(self):
     if PY3:
         vector_tile = b'\x1aI\n\x05water\x12\x1a\x08\x01\x12\x06\x00\x00\x01\x01\x02\x02\x18\x03"\x0c\t\x00\[email protected]\x1a\x00\x01\x02\x00\x00\x02\x0f\x1a\x03foo\x1a\x03baz\x1a\x03uid"\x05\n\x03bar"\x05\n\x03foo"\x02 {(\x80 x\x02'  # noqa
     else:
         vector_tile = '\x1aI\n\x05water\x12\x1a\x08\x01\x12\x06\x00\x00\x01\x01\x02\x02\x18\x03"\x0c\t\x00\[email protected]\x1a\x00\x01\x02\x00\x00\x02\x0f\x1a\x03foo\x1a\x03baz\x1a\x03uid"\x05\n\x03bar"\x05\n\x03foo"\x02 {(\x80 x\x02'  # noqa
     self.assertEqual(mapbox_vector_tile.decode(vector_tile), {
         'water': {
             'version': 2,
             'extent': 4096,
             'features': [{
                 'geometry': {
                     'type': 'Polygon',
                     'coordinates': [
                         [[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]
                     ]
                 },
                 'properties': {
                     'foo': 'bar',
                     'baz': 'foo',
                     'uid': 123
                 },
                 'id': 1,
                 'type': 3
             }],
         },
     })
开发者ID:ptpt,项目名称:mapbox-vector-tile,代码行数:26,代码来源:test_decoder.py


示例6: test_make_valid_self_crossing

    def test_make_valid_self_crossing(self):
        from mapbox_vector_tile import encode
        from mapbox_vector_tile.encoder import on_invalid_geometry_make_valid
        import shapely.geometry
        import shapely.wkt
        geometry = 'POLYGON ((10 10, 20 10, 20 20, 15 15, 15 5, 10 10))'
        shape = shapely.wkt.loads(geometry)
        self.assertFalse(shape.is_valid)
        feature = dict(geometry=shape, properties={})
        source = dict(name='layername', features=[feature])
        pbf = encode(source,
                     on_invalid_geometry=on_invalid_geometry_make_valid)
        result = decode(pbf)
        self.assertEqual(1, len(result['layername']['features']))
        valid_geometries = result['layername']['features'][0]['geometry']
        geom_type = result['layername']['features'][0]['type']
        self.assertEqual(3, geom_type)  # 3 means POLYGON
        self.assertEqual(valid_geometries['type'], 'MultiPolygon')
        multipolygon = shapely.geometry.shape(valid_geometries)
        self.assertTrue(multipolygon.is_valid)

        total_area = 0
        for p in multipolygon.geoms:
            self.assertTrue(p.is_valid)
            self.assertGreater(p.area, 0)
            total_area += p.area

        self.assertEquals(50, total_area)
        self.assertEquals(50, multipolygon.area)
开发者ID:ptpt,项目名称:mapbox-vector-tile,代码行数:29,代码来源:test_encoder.py


示例7: parse_data

    def parse_data(self, x, y, zoom, data):
        self.x = x
        self.y = y
        self.zoom = zoom

        tile = mapbox_vector_tile.decode(data)
        self.extent = tile["osm"]["extent"]
        for feature in tile["osm"]["features"]:
            self._handle_feature(feature)
开发者ID:Mapkin,项目名称:osmqa-parser,代码行数:9,代码来源:parser.py


示例8: test_encode_multipolygon

    def test_encode_multipolygon(self):
        geometry = 'MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))'
        expected_result = '\x1a9\n\x05water\x12\x0e\x18\x03"\n\tP\xb0?\x12\'\t2\x1e\x0f\x12\x1b\x18\x03"\x17\t(\xba?"\x13\n\x00((\n\x1e\x1d\x0f\t\x1d\x00\x12\x13\n\x00\x13\x0f(\x80 x\x02'
        result = mapbox_vector_tile.encode([
            dict(name='water',
                 features=[dict(geometry=geometry, properties={})])])
        self.assertEqual(expected_result, result)

        decoded = mapbox_vector_tile.decode(result)
        features = decoded['water']
        self.assertEqual(2, len(features))
开发者ID:alukach,项目名称:mapbox-vector-tile,代码行数:11,代码来源:test_encoder.py


示例9: test_too_small_linestring

 def test_too_small_linestring(self):
     from mapbox_vector_tile import encode
     from mapbox_vector_tile.encoder import on_invalid_geometry_make_valid
     import shapely.wkt
     shape = shapely.wkt.loads(
         'LINESTRING(-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932)')  # noqa
     features = [dict(geometry=shape, properties={})]
     pbf = encode({'name': 'foo', 'features': features},
                  on_invalid_geometry=on_invalid_geometry_make_valid)
     result = decode(pbf)
     features = result['foo']['features']
     self.assertEqual(0, len(features))
开发者ID:ptpt,项目名称:mapbox-vector-tile,代码行数:12,代码来源:test_encoder.py


示例10: test_too_small_geometry

 def test_too_small_geometry(self):
     from mapbox_vector_tile import encode
     from mapbox_vector_tile.encoder import on_invalid_geometry_make_valid
     import shapely.wkt
     shape = shapely.wkt.loads(
         'LINESTRING (3065.656210384849 3629.831662879646, 3066.458953567231 3629.725941289478)')  # noqa
     features = [dict(geometry=shape, properties={})]
     pbf = encode({'name': 'foo', 'features': features},
                  on_invalid_geometry=on_invalid_geometry_make_valid)
     result = decode(pbf)
     features = result['foo']['features']
     self.assertEqual(0, len(features))
开发者ID:ptpt,项目名称:mapbox-vector-tile,代码行数:12,代码来源:test_encoder.py


示例11: test_invalid_geometry_ignore

 def test_invalid_geometry_ignore(self):
     from mapbox_vector_tile import encode
     from mapbox_vector_tile.encoder import on_invalid_geometry_ignore
     import shapely.wkt
     geometry = 'POLYGON ((10 10, 20 10, 20 20, 15 15, 15 5, 10 10))'
     shape = shapely.wkt.loads(geometry)
     self.assertFalse(shape.is_valid)
     feature = dict(geometry=shape, properties={})
     source = dict(name='layername', features=[feature])
     pbf = encode(source, on_invalid_geometry=on_invalid_geometry_ignore)
     result = decode(pbf)
     self.assertEqual(0, len(result['layername']['features']))
开发者ID:fgcartographix,项目名称:mapbox-vector-tile,代码行数:12,代码来源:test_encoder.py


示例12: test_encode_feature_with_id

 def test_encode_feature_with_id(self):
     geometry = 'POINT(1 1)'
     expected_result = '\x1a\x18\n\x05water\x12\n\x08*\x18\x01"\x04\t\x02\xfe?(\x80 x\x02'
     result = mapbox_vector_tile.encode([
         dict(name='water',
              features=[dict(geometry=geometry, properties={}, id=42)])])
     self.assertEqual(expected_result, result)
     decoded = mapbox_vector_tile.decode(result)
     features = decoded['water']
     self.assertEqual(1, len(features))
     feature = features[0]
     self.assertEqual(42, feature['id'])
开发者ID:alukach,项目名称:mapbox-vector-tile,代码行数:12,代码来源:test_encoder.py


示例13: mapper

    def mapper(self, x, y, zoom, data):
        if data is None:
            return 0

        tile = mapbox_vector_tile.decode(data)

        count = 0
        if tile.get('buildings'):
            count += len(tile['buildings'])
        if tile.get('roads'):
            count += len(tile['roads'])

        return count
开发者ID:jwass,项目名称:tile-reduce-py,代码行数:13,代码来源:count.py


示例14: test_quantize_makes_mutlipolygon_invalid

 def test_quantize_makes_mutlipolygon_invalid(self):
     from mapbox_vector_tile import encode
     from mapbox_vector_tile.encoder import on_invalid_geometry_make_valid
     import shapely.wkt
     shape = shapely.wkt.loads('MULTIPOLYGON (((656510.8206577231 5674684.979891453, 656511.16 5674685.9, 656514.1758819892 5674684.979891453, 656510.8206577231 5674684.979891453)), ((657115.9120547654 5674684.979891453, 657118.85 5674690, 657118.0689111941 5674684.979891453, 657115.9120547654 5674684.979891453)))')  # noqa
     quantize_bounds = (645740.0149532147, 5674684.979891453, 665307.8941942193, 5694252.8591324575)  # noqa
     features = [dict(geometry=shape, properties={})]
     pbf = encode({'name': 'foo', 'features': features},
                  quantize_bounds=quantize_bounds,
                  on_invalid_geometry=on_invalid_geometry_make_valid)
     result = decode(pbf)
     features = result['foo']['features']
     self.assertEqual(1, len(features))
开发者ID:ptpt,项目名称:mapbox-vector-tile,代码行数:13,代码来源:test_encoder.py


示例15: test_quantize_and_y_coord_down

    def test_quantize_and_y_coord_down(self):
        from mapbox_vector_tile import decode
        from mapbox_vector_tile import encode
        props = dict(foo='bar')
        shape = 'POINT(30 30)'
        feature = dict(geometry=shape, properties=props)
        features = [feature]
        source = dict(name='layername', features=features)
        bounds = 0.0, 0.0, 50.0, 50.0
        pbf = encode(source, quantize_bounds=bounds, y_coord_down=True)

        result_decode_no_flip = decode(pbf, y_coord_down=True)
        act_feature = result_decode_no_flip['layername']['features'][0]
        act_geom = act_feature['geometry']
        exp_geom = [[2458, 2458]]
        self.assertEqual(exp_geom, act_geom)

        result_decode_flip = decode(pbf)
        act_feature = result_decode_flip['layername']['features'][0]
        act_geom = act_feature['geometry']
        exp_geom = [[2458, 1638]]
        self.assertEqual(exp_geom, act_geom)
开发者ID:fgcartographix,项目名称:mapbox-vector-tile,代码行数:22,代码来源:test_encoder.py


示例16: test_y_coord_down

 def test_y_coord_down(self):
     from mapbox_vector_tile import decode
     from mapbox_vector_tile import encode
     props = dict(foo='bar')
     shape = 'POINT(10 10)'
     feature = dict(geometry=shape, properties=props)
     features = [feature]
     source = dict(name='layername', features=features)
     pbf = encode(source, y_coord_down=True)
     result = decode(pbf, y_coord_down=True)
     act_feature = result['layername']['features'][0]
     act_geom = act_feature['geometry']
     exp_geom = [[10, 10]]
     self.assertEqual(exp_geom, act_geom)
开发者ID:fgcartographix,项目名称:mapbox-vector-tile,代码行数:14,代码来源:test_encoder.py


示例17: test_custom_extent

 def test_custom_extent(self):
     from mapbox_vector_tile import decode
     from mapbox_vector_tile import encode
     props = dict(foo='bar')
     shape = 'POINT(10 10)'
     feature = dict(geometry=shape, properties=props)
     features = [feature]
     source = dict(name='layername', features=features)
     bounds = 0.0, 0.0, 10.0, 10.0
     pbf = encode(source, quantize_bounds=bounds, extents=50)
     result = decode(pbf)
     act_feature = result['layername']['features'][0]
     act_geom = act_feature['geometry']
     exp_geom = [[50, 50]]
     self.assertEqual(exp_geom, act_geom)
开发者ID:fgcartographix,项目名称:mapbox-vector-tile,代码行数:15,代码来源:test_encoder.py


示例18: test_quantize

 def test_quantize(self):
     from mapbox_vector_tile import decode
     from mapbox_vector_tile import encode
     props = dict(foo='bar')
     shape = 'POINT(15 15)'
     feature = dict(geometry=shape, properties=props)
     features = [feature]
     source = dict(name='layername', features=features)
     bounds = 10.0, 10.0, 20.0, 20.0
     pbf = encode(source, quantize_bounds=bounds)
     result = decode(pbf)
     act_feature = result['layername']['features'][0]
     act_geom = act_feature['geometry']
     exp_geom = {'type': 'Point', 'coordinates': [2048, 2048]}
     self.assertEqual(exp_geom, act_geom)
开发者ID:ptpt,项目名称:mapbox-vector-tile,代码行数:15,代码来源:test_encoder.py


示例19: test_decoder

	def test_decoder(self):
		vector_tile = '\x1aI\n\x05water\x12\x1a\x08\x01\x12\x06\x00\x00\x01\x01\x02\x02\x18\x03"\x0c\t\x00\[email protected]\x1a\x00\x01\x02\x00\x00\x02\x0f\x1a\x03foo\x1a\x03baz\x1a\x03uid"\x05\n\x03bar"\x05\n\x03foo"\x02 {(\x80 x\x02'
		self.assertEqual(mapbox_vector_tile.decode(vector_tile), 
				{
					'water': [{
						'geometry': [[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]], 
						'properties': {
							'foo': 'bar', 
							'baz': 'foo', 
							'uid': 123
						}, 
						'id': 1
					}]
				}
			)
开发者ID:JulieGoldberg,项目名称:mapbox-vector-tile,代码行数:15,代码来源:test_decoder.py


示例20: test_custom_rounding_function

    def test_custom_rounding_function(self):
        from mapbox_vector_tile import decode
        from mapbox_vector_tile import encode
        props = dict(foo='bar')
        shape = 'POINT(10 10)'
        feature = dict(geometry=shape, properties=props)
        features = [feature]
        source = dict(name='layername', features=features)
        bounds = 0.0, 0.0, 10.0, 10.0
        # A really bad, custom "rounding" function
        pbf = encode(source, quantize_bounds=bounds, round_fn=lambda x: 5)
        result = decode(pbf)

        act_feature = result['layername']['features'][0]
        act_geom = act_feature['geometry']
        exp_geom = [[5, 5]]
        self.assertEqual(exp_geom, act_geom)
开发者ID:fgcartographix,项目名称:mapbox-vector-tile,代码行数:17,代码来源:test_encoder.py



注:本文中的mapbox_vector_tile.decode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mapbox_vector_tile.encode函数代码示例发布时间:2022-05-27
下一篇:
Python map.Map类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap