[GIS] How to merge layers from two vector tiles with Mapnik

mapboxmapnikvector-tiles

I'm using Mapnik + Mapbox nodejs stack. Given two vector tiles (PBFs) for the same location/zoom, with some layers having the same name in both. How do I merge them into one PBF tile – replacing identically named layers in the first tile with the ones from the second tile?

Update:
I found that I can add layers via GeoJson, but it seems awfully inefficient: addGeoJSON does not replace existing layer, but adds a new one (even if the same name already exists), so I have to export each layer to JSON and re-add them to a new tile:

newVectorTile.addGeoJSON(vectorTile.toGeoJSON('water'), 'water');

Best Answer

2 years later but I've had some success doing what I think you want done using the tile-join tool in mapbox tippecanoe. It's opensource.

https://github.com/mapbox/tippecanoe#tile-join

Tile-join is a tool for copying and merging vector mbtiles files and for joining new attributes from a CSV file to existing features in them.

It reads the tiles from an existing .mbtiles file or a directory of tiles, matches them against the records of the CSV (if one is specified), and writes out a new tileset.

If you specify multiple source mbtiles files or source directories of tiles, all the sources are read and their combined contents are written to the new mbtiles output. If they define the same layers or the same tiles, the layers or tiles are merged.