A small NodeJS cli tool to inspect and optimize Mapbox MBTiles files used to encode Mapbox Vector Tiles. You can find an explanation on what it does and how it works in this blog post
Clone this repository and run npm install
This tool has two main functionalities: inspecting a vector tile to see if it conforms to Mapbox's recommendations of an average tile size of 50KB and a maximum tile size of 500KB and optimizing a vector tile to be used with a fixed style.
When running the tool with the -m file.mbtiles argument, the inspection mode will be started. This mode is used for interactively inspecting the contents of a Vector Tile.
After the file is read, some metadata about the file, the layers list and a summary table are shown. With this table you can get a first glimpse of how well your Vector Tile is doing.
Where:
We can then get more information about a given level to see the distribution of its tiles by size on a 10-bucket histogram.
Where:
Afterwards we can see which are the specific tiles that fall inside a given bucket
and selecting one of them we can see a summary of the tile contents
where the number of layers and the number of features and properties of each layer are shown.
When running the tool with the -m file.pbf and -x X -y Y -z Z arguments, each layer of the tile contents will be converted to geojson and printed on the console
When running the tool with the -u url.pbf and -x X -y Y -z Z arguments, the pbf will be downloaded and each layer of the single tile will be converted to geojson and printed on the console
When running the tool with the -m file.mbtiles and -s style.json arguments, the optimization mode will be started. This mode is used for optimizing a Vector Tile when used in conjunction with a style that follows Mapbox Style Specification.
It reads both the Vector Tile and style and removes all the layers and features that are not visible, either because they are not used or because the style configuration makes them not renderable. When the process is finished the number of features removed in each zoom level and the levels where each layer has been removed from are shown.
Note: To use the optimization tool it's better to run the --max-old-space-size
NodeJS argument to increase NodeJS process heap space as the entire Vector Tile is loaded and decompressed when working.
node --max-old-space-size=16386 index.js -m files/input.mbtiles -s files/style.json -o files/output.mbtiles
When running the tool with the -x X -y Y -z Z -l layerName -t tolerance arguments, the simplification mode will be started. This mode is used for simplifying a layer on a given tile. Note: The tolerance value is in degrees (1º is aproximately 110 meters) and tells the algorithm that two points with a distance lower than the tolerance value should be merged.
When the process is finished, the results of the simplification are shown.