Tuesday 11 July 2017

javascript - Can multiple MapBox vector tile mbtiles be merged just using SQLite?


Is it possible to combine two vector mbtiles files using just SQLite?


I noticed this question Joining several raster .mbtiles? but it does not seem to work with vector files.


I also came across this script Patch mbtiles which seems to support the idea that it should be possible.


In my use case, I want to be able to merge mbtiles on the client side (in a Cordova app with sqlite) without having to involve any operations on the server.


For testing I have two .mbtiles, one covering Maryland and another covering Pennsylvania. Both contain the same layers and zoom levels.



If I merge the map and images tables as shown in the patch file above and view the resulting map in mapbox gl js, there is over a hundred mile gap between the top of Maryland and where the map features start rendering again. If I attempt to merge in Virgina it doesn't display at all.


What am I missing?



Answer



The patch script will replace tiles in the destination with tiles from the source. If those tiles cover a state border, the features outside the source state in the destination state are essentially deleted from the tile. That's why you're getting the empty space above Maryland - those are the border tiles that also cover Pennsylvania and it's replacing the Pennsylvania tile instead of merging the features from both states.


To merge them you would have to take every tile in the total bounds of your coverage, select that tile from the tiles table from each overlapping state, serialize the features, merge them, and then convert and write the new BLOB to the target tile.


You should be able to just insert rows from one metadata table to the other.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...