I have a folder with a gdal2tiles output: 6 levels of zoom (and folders), with subfolders and .png tiles.

Is there a gdal tool to merge in a single geotiff file these .png tiles?

3 Answers 3


My solution requires a fair amount of work to get there, but this should work.

  1. Set up TileCache, GeoWebCache, or MapProxy to consume the tile cache and output a WMS service.

  2. You could then consume this WMS service with QGis or another desktop GIS that supports WMS.

  3. Create your printable map using the desktop GIS.

  • Hi David, thank you very much. I wanted to know if there was a direct inverse method. Apparently not. I'm sure your method works. Thank you.
    – aborruso
    Jan 5, 2011 at 9:36
  • I am definitely not saying that this is the best or most efficient way, but it should work. My thought is, that if there is already existing software to do the job, that might be easier than writing it myself...
    – DavidF
    Jan 5, 2011 at 14:12
  • David once again thank you. I am definitely not saying that your solution was wrong. Another good solution similar to yours is to use WMS format: gdal.org/frmt_wms.html It has support for TMS Minidriver. It is designed primarily to support the users of the TMS Specification. Best regards
    – aborruso
    Jan 5, 2011 at 16:18
  • Hi David, only to say that I have used MapProxy to consume my tile cache source tiles. Then I have used a GDAL WMS minidriver to read my source layer via MapProxy WMS. I have not been able to use directly GDAL TMS minidriver; probably for some configuration error of mine. Thank you
    – aborruso
    Sep 15, 2012 at 10:27

Just curious; what are you trying to accomplish? If you used gdal2tiles, the original image will be the result. You would be going form a single image, to a bunch of tiles, back to a single image... I am guessing there is a more efficient way!

  • This is more of a comment than an answer. Consider posting as a comment on the question instead.
    – Sean
    Jan 3, 2011 at 20:12
  • 1
    Hi Darren, I do not have the original Image. I have had only these tiles, and I need to compose a print layout to produce a printed map.
    – aborruso
    Jan 4, 2011 at 7:46

gdal_merge. It should be included with most distributions of GDAL.

You'll have to generate a world file for each image first. You would use just the images from the largest scale directory (6) each subdirectory corresponds to a column of the image and each the highest number image in the subdirectory is the top row. There should be an XML file from the gdal2tiles output that has the extents. You'll have to calculate the upper left pixel coordinate of each image and pixel size (probably 1) from that.

So you might have something like:


where the lines correspond to these values from the XML file:

units-per-pixel for the lowest level tileset
0 (no rotation)
0 (no rotation)
negative units-per-pixel for the lowest level tileset
Origin x
BoundingBox maxY

This will take some scripting. The world files should end in .pgw, .pngw or .wld.

  • It seems to me (I'm not an expert) that gdal_merge needs geospatial files as source. The output of gdal2tiles are files and folders following OSGeo Tile Map Service Specification. The single png created from gdal2tiles does not contain any geospatial information. I know the bounding box of the mosaic of my tiles, the SRS, and the resolution of every zoom level. Then gdal_merge - I think - is not able to associate any spatial information to the single .png file I have, and it cannot build a mosaic image. Thank you
    – aborruso
    Jan 4, 2011 at 10:54
  • My bad, I assumed they would have world files or embedded georeference. I updated the answer to explain a bit about how to add world files.
    – Sean
    Jan 4, 2011 at 19:07

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.