Skip to content
Claus Höfele edited this page Dec 5, 2015 · 10 revisions

Export Vector Data from Mapbox Studio

Mapbox Studio allows to export vector data sources in the MBTiles format:

  • Open or create new source project (note: don't use a style project)
  • Save project
  • Go to Settings and click Export to MBTiles
  • Download and save the exported data

The resulting file is an SQLite database that includes the vector data.

Decode Vector Data in MBTiles Format

Use mb-util to extract pbf data

  • Install mb-util with easy_install mbutil GitHub
  • Convert mbtiles file, e.g. mb-util roads_1690.mbtiles roads_1690. This will create a directory with tiles for all zoom levels.
  • Unzip a tile (e.g. by renaming 21493.png into 21493.zip and double-clicking on it)
  • Decode the tile in pbf format via the protoc tool mentioned below

Use SQLite to extract pbf data

MBTiles files can be read with the sqlite3 tool (preinstalled on Mac OS X).

$ sqlite3 test.mbtiles 
SQLite version 3.8.5 2014-08-15 22:37:57
Enter ".help" for usage hints.
sqlite> .tables
geocoder_data  grid_key       grids          keymap         metadata     
grid_data      grid_utfgrid   images         map            tiles        

The MBTiles database contains vector data if the format specifier returns pbf (i.e. Protocol Buffers):

sqlite> select value from metadata where name = "format";
pbf

Use the following steps to export vector data:

  • .dump images, then choose a tile ID to export (e.g. f93dd1408623fbc191025a00e057a338)
  • Use this tile ID to extract the zipped PBF data into a file (e.g. named tile_data.zip)
sqlite3 de.mbtiles "select quote(images.tile_data) from images where images.tile_id = 'f93dd1408623fbc191025a00e057a338';" | cut -d "'" -f2 | xxd -r -p > tile_data.zip
  • Unzip the resulting file by double-clicking on it (results in a file called tile_data)

Decode pbf data

  • Install the protobuffer tool if necessary via brew install protobuf
  • Download the latest PBF schema file for Mapbox's vector tiles
  • Use the schema file to look at the contents of the data:
$ protoc --decode=vector_tile.Tile vector_tile.proto < tile_data
layers {
  name: "de"
  features {
    id: 1
    tags: 0
    tags: 0
    type: POLYGON
    geometry: 9
    geometry: 8448
    geometry: 255
    geometry: 34
    geometry: 0
    geometry: 8704
    geometry: 8703
    geometry: 0
    geometry: 0
    geometry: 8703
    geometry: 8704
    geometry: 0
    geometry: 15
  }
  keys: "name"
  values {
    string_value: "Germany"
  }
  extent: 4096
  version: 1
}

Clone this wiki locally