本文整理汇总了Python中mapbox_vector_tile.encode函数的典型用法代码示例。如果您正苦于以下问题:Python encode函数的具体用法?Python encode怎么用?Python encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: encode
def encode(file, features, bounds, layer_name=''):
layers = []
layers.append(get_feature_layer(layer_name, features))
if bounds:
data = mapbox_vector_tile.encode(layers, quantize_bounds=bounds)
else:
data = mapbox_vector_tile.encode(layers)
file.write(data)
开发者ID:jbants,项目名称:TileStache,代码行数:9,代码来源:pbf.py
示例2: test_invalid_geometry_raise
def test_invalid_geometry_raise(self):
from mapbox_vector_tile import encode
from mapbox_vector_tile.encoder import on_invalid_geometry_raise
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])
with self.assertRaises(Exception):
encode(source, on_invalid_geometry=on_invalid_geometry_raise)
开发者ID:fgcartographix,项目名称:mapbox-vector-tile,代码行数:11,代码来源:test_encoder.py
示例3: test_with_invalid_geometry
def test_with_invalid_geometry(self):
expected_result = ('Can\'t do geometries that are not wkt, wkb, or '
'shapely geometries')
with self.assertRaises(NotImplementedError) as ex:
mapbox_vector_tile.encode([{
"name": self.layer_name,
"features": [{
"geometry": "xyz",
"properties": self.feature_properties
}]
}])
self.assertEqual(str(ex.exception), expected_result)
开发者ID:rory,项目名称:mapbox-vector-tile,代码行数:12,代码来源:test_encoder.py
示例4: test_with_invalid_geometry
def test_with_invalid_geometry(self):
geometry = "xyz"
expected_result = 'Can\'t do geometries that are not wkt or wkb'
with self.assertRaises(NotImplementedError) as ex:
mapbox_vector_tile.encode([{
"name": self.layer_name,
"features": [{
"geometry": geometry,
"properties": self.feature_properties
}]
}])
self.assertEqual(ex.exception[0], expected_result)
开发者ID:hkrishna,项目名称:mapbox-vector-tile,代码行数:12,代码来源:test_encoder.py
示例5: _errors_mvt
def _errors_mvt(db, results, z, min_lon, min_lat, max_lon, max_lat, limit):
if not results or len(results) == 0:
return None
else:
limit_feature = []
if len(results) == limit and z < 18:
limit_feature = [{
"name": "limit",
"features": [{
"geometry": Point((min_lon + max_lon) / 2, (min_lat + max_lat) / 2)
}]
}]
issues_features = []
for res in sorted(results, key=lambda res: -res["lat"]):
issues_features.append({
"geometry": Point(res["lon"], res["lat"]),
"properties": {
"issue_id": res["id"],
"item": res["item"] or 0,
"class": res["class"] or 0}
})
return mapbox_vector_tile.encode([{
"name": "issues",
"features": issues_features
}] + limit_feature, quantize_bounds=(min_lon, min_lat, max_lon, max_lat))
开发者ID:osm-fr,项目名称:osmose-frontend,代码行数:27,代码来源:map.py
示例6: 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
示例7: 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
示例8: 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
示例9: 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
示例10: encode
def encode(file, features, coord, layer_name=''):
layers = []
layers.append(get_feature_layer(layer_name, features))
data = mapbox_vector_tile.encode(layers)
file.write(data)
开发者ID:TileStache,项目名称:TileStache,代码行数:7,代码来源:pbf.py
示例11: test_encoder
def test_encoder(self):
expected_result = '\x1aG\n\x05water\x12\x18\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.encode([{
"name": self.layer_name,
"features": [{
"geometry": self.feature_geometry,
"properties": self.feature_properties
}]
}]), expected_result)
开发者ID:alukach,项目名称:mapbox-vector-tile,代码行数:9,代码来源:test_encoder.py
示例12: test_with_wkt
def test_with_wkt(self):
geometry = "LINESTRING(-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932)"
expected_result = '\x1aE\n\x05water\x12\x16\x12\x06\x00\x00\x01\x01\x02\x02\x18\x02"\n\t\x8d\x01\xaa?\x12\x00\x00\x00\x00\x1a\x03foo\x1a\x03baz\x1a\x03uid"\x05\n\x03bar"\x05\n\x03foo"\x02 {(\x80 x\x02'
self.assertEqual(mapbox_vector_tile.encode([{
"name": self.layer_name,
"features": [{
"geometry": geometry,
"properties": self.feature_properties
}]
}]), expected_result)
开发者ID:alukach,项目名称:mapbox-vector-tile,代码行数:10,代码来源:test_encoder.py
示例13: test_encode_float_little_endian
def test_encode_float_little_endian(self):
geometry = "LINESTRING(-71.160281 42.258729,-71.160837 42.259113,-71.161144 42.25932)"
expected_result = '\x1a\\\n\x05water\x12\x18\x12\x08\x00\x00\x01\x01\x02\x02\x03\x03\x18\x02"\n\t\x8d\x01\xaa?\x12\x00\x00\x00\x00\x1a\x08floatval\x1a\x03foo\x1a\x03baz\x1a\x03uid"\t\x19n\x86\x1b\xf0\xf9!\[email protected]"\x05\n\x03bar"\x05\n\x03foo"\x02 {(\x80 x\x02'
self.feature_properties['floatval'] = 3.14159
self.assertEqual(mapbox_vector_tile.encode([{
"name": self.layer_name,
"features": [{
"geometry": geometry,
"properties": self.feature_properties
}]
}]), expected_result)
开发者ID:alukach,项目名称:mapbox-vector-tile,代码行数:11,代码来源:test_encoder.py
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: 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
示例19: 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
示例20: merge
def merge(file, feature_layers, bounds):
'''
Retrieve a list of protobuf vector tile responses and merge them into one.
get_tiles() retrieves data and performs basic integrity checks.
'''
layers = []
for layer in feature_layers:
layers.append(get_feature_layer(layer['name'], layer['features']))
data = mapbox_vector_tile.encode(layers)
file.write(data)
开发者ID:jbants,项目名称:TileStache,代码行数:13,代码来源:pbf.py
注:本文中的mapbox_vector_tile.encode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论