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:

  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?


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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