Skip to content

Instantly share code, notes, and snippets.

@pepijndevos
Last active August 11, 2022 12:13
Show Gist options
  • Save pepijndevos/4269ba88c054ceee9a08bacfd23a5c90 to your computer and use it in GitHub Desktop.
Save pepijndevos/4269ba88c054ceee9a08bacfd23a5c90 to your computer and use it in GitHub Desktop.
Parse mapbox vector tiles with minipb on micropython
import minipb
import zlib
value = (('string_value', 'U'),
('float_value', 'f'),
('double_value', 'd'),
('int_value', 't'),
('uint_value', 'T'),
('sint_value', 'z'),
('bool_value', 'b'))
feature = (('id', 'T'),
('tags', '#T'),
('type', 't'),
('geometry', '#T'))
layer = (('name', '*U'),
('features', '+[', feature, ']'),
('keys', '+U'),
('values', '+[', value, ']'),
('extent', 'T'),
('_', 'x9'),
('version', '*T'))
tile = (('_', 'x2'), ('layers', '+[', layer, ']'))
wire = minipb.IterWire(tile)
def unpack(path):
with open(path, 'rb') as f:
# adjust between 16+ 8..15 to allocate buffer
raw = zlib.DecompIO(f, 16+15)
yield from wire.decode(raw)
for x in unpack('/sd/vtiles/14/8414/5384.pbf'):
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment