2

So I have hit a snag. I wish to merge multiple XYZ tile sets together. Meaning I have multiple directories which contain tiles in the format /zoom/x/y.png.

I tried just copy and pasting them in to the same directory, but it appears that some of the tiles have clashing file names, and thus I lose some tiles with this approach. For instance, nearly all the sets will have the tile 1/1/1.png, and this will be overwritten every time.

I am taking this route because the tiles are being generated from multiple VRTs that span a wide area, each with large swathes of NODATA between them. So when I end up tiling them, 90% of the tiles it generates are empty bogus. Normally this wouldn't be a big issue, but at the scale I am at it ends up adding many hours to the processing time.

One solution I think would be to convert all the tile sets to use a single origin, determined by analyzing the VRT sources for the different tilesets. Then I would go through all the tiles in each of the tilesets and convert their /zoom/x/y.png path to use the new, recalculated origin.

The main function for converting the tile would look something like this:

getTilesNewXYZPath(
  originalTileOriginLat,  # Original tile's origin latitude
  originalTileOriginLon,  # Original tile's origin longitude
  originalTileX,          # Original tile's x coord at zoom level z
  originalTileY,          # Original tile's y coord at zoom level z
  originalTileZ,          # Original tile's zoom level (z) 
  newTileOriginLat,       # Origin latitude to convert to
  newTileOriginLon,       # Origin longitude to convert to
)

How would I do this? Does anybody have some math they could point me towards, besides that on the OSGeo wiki? Or am I going about this the whole wrong way, and need to use a different strategy? Or even worse, is the overwriting behavior I am experiencing not caused by gdal2tiles.py?

3 Answers 3

1

Maptiler (made by creators of gdal2tiles) has a solution via their software in which overlapping tile sets can be merged together. See https://www.maptiler.com/how-to/merge-mbtiles/. However, it would be nice if there were an open-source solution, for those who've generated tilesets from rasters that have adjacent boundaries. When working with large areas (as you mentioned) it is not practical to tile the entire area in one command.

0

Did you find a solution to this, apart from the 35000 usd maptiler pro? I am facing the same challenge with maptiles for a leaflet map where the borders between parts of the map takes so long to fix today. And would like to have an automated solution before creating bigger maps.

0

This perl utility works for me, it uses ImageMagick to composite the "clashing" images. It will successfully merge together all 54 tile sets that I'm generating from FAA Digital Raster charts, after which I can use mbutil to load a mbtiles database.

https://github.com/jlmcgraw/aviationCharts/blob/master/merge_tile_sets.pl

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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