2

I downloaded the sample mbtiles data from https://www.mapbox.com/help/data/trails.mbtiles

In the metadata of this file I found that the format is pbf.

enter image description here

But if I directly query the tile_data column in images table of it, and use some tools such as vector-tile-base to decode it, it will return errors with this message: google.protobuf.message.DecodeError: Wrong wire type in tag. (I have tested the tool on some mvt files and it works with no problem)

So how should I get the decoded pbf data from .mbtiles files?

Appendix: Decoding code here:

import sqlite3
import vector_tile_base as vtb
tile_db = sqlite3.connect('trails.mbtiles')
cursor = tile_db.cursor()
one_example = cursor.execute('select tile_data from images limit 1').fetchall()[0][0]
vtb.VectorTile(one_example)

1 Answer 1

1

I read the specification of mbtiles from this github url and finally find that in mbtiles files the pbf file is compressed by gzip, so it is neccessary to decompress it at first and then decode it using some protobuf tools.

import sqlite3
import vector_tile_base as vtb
import gzip
tile_db = sqlite3.connect('trails.mbtiles')
cursor = tile_db.cursor()
one_example = cursor.execute('select tile_data from images limit 1').fetchall()[0][0]
vtb.VectorTile(gzip.decompress(one_example[0]))
>>> <vector_tile_base.engine.VectorTile at 0x11f378eb8>
2
  • The official repo for vector_tile_base is https://github.com/mapbox/vector-tile-base.
    – J'e
    May 31 at 12:31
  • What is the proper way to use vector_tile_base? Do install in as a standalone package or do I install the entire mapbox-vector-tile package?
    – J'e
    May 31 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.