This library encodes and decodes Mapbox Vector Tiles. It is intended for use by developers with clear understanding of the Vector Tile format. The code is written as a pure python implementation with support of the google protobuf python format.
- Google protobuf python bindings
Install the python locally with pip:
pip install -e .
To run tests use pytest:
pytest
Some very simple code examples
There is an example encoding provided in examples
and can be used to ecode a .mvt
file.
python examples/encode.py my.mvt
import vector_tile_base
import sys
vt = vector_tile_base.VectorTile()
layer = vt.add_layer('my_locations')
feature = layer.add_point_feature()
feature.add_points([[10,10],[20,20]])
feature.id = 1
feature.attributes = { 'type': 1, 'name': 'my_points' }
encoded_tile = vt.serialize()
f = open(sys.argv[1], "wb")
f.write(encoded_tile)
f.close()
There is an example decoding provided in examples
and can be used to decode a .mvt
file.
python examples/decode.py my.mvt
import vector_tile_base
import sys
f = open(sys.argv[1], "rb")
raw_tile = f.read()
f.close()
vt = vector_tile_base.VectorTile(raw_tile)
for l in vt.layers:
print(l.name)
for f in l.features:
print(f.type)
print(f.attributes)
print(f.get_geometry())