Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I need to merge about 760 png files into one and am looking at using gdal for this. This is related to the following question Getting a constant background color for transparency

P:\2012\183_TownPlanning_Symbology\Working\Raster_Layer_Creation\tests\BA\25k>gd
al_merge -o ba_25k_gdal -of png -init "255 255 255" *.png

should work but gives

Format driver png does not support creation and piecewise writing. Please select a format that does, such as GTiff (the default) or HFA (Erdas Imag ine).

When I switch to HFA or GTiff format and try

P:\2012\183_TownPlanning_Symbology\Working\Raster_Layer_Creation\tests\BA\25k>gd
al_merge -o ba_25k_gdal -init "255 255 255" *.png

I get

ERROR 4: `*.png' does not exist in the file system, and is not recognised as a supported dataset name.

Traceback (most recent call last): File "C:\OSGeo4W\bin\gdal_merge.py", line 509, in sys.exit(main()) File "C:\OSGeo4W\bin\gdal_merge.py", line 392, in main ulx = file_infos[0].ulx IndexError: list index out of range

but the format seems correct according to http://www.gdal.org/gdal_merge.html

How can I tell it to include all png files in the directory? I can pipe *.png > png_list.txt but can I get gdal to read a list from a text file? So does this mean merging png's in gdal is not possible?

Are there other ways of achieving this? I have tried Global Mapper but that estimates a day to complete it and I am just running it. Erdas crashed. I am trying ArcMap 10.1 import into mosaic dataset and export as raster -still running but estimates a 35gb png file.

This is from 161 tiles (25k resolution) over 65,000 sq km. But the source png's are only 73Mb.

share|improve this question
    
35GB does not seems to much, it depends on shape. Raster size is not a sum of input rasters. Size depends on envelope which describe all raster that you throw in. Also, ArcGIS use GDAL for plenty of raster work (not sure if for mosaics). If all properties are set precisely Arc will produce same raster as GDAL. I did compare speed of GDAL_MERGE and ARC mosaics. It was comparable, as speed of mosicing mostly depends on raster size (cell count). GDAL_Merge and arc mosaic add raster one by one which is just time consuming. There is also GDALWARP if you need more variety. –  Tomek Oct 23 '12 at 18:45
    
If you want to speed up merging/mosaicing process, you may try to merge closest rasters first rather than let the program decide which go first. This will prevent from merging extreme raster at the begining and will consume less time in total. –  Tomek Oct 25 '12 at 6:02
add comment

3 Answers 3

up vote 2 down vote accepted

Option -n should be followed by only one pixel value not three. Or better use -init option

share|improve this answer
    
Thanks, I noticed this and changed the code/tried but that doesn't resolve the main issue..."Format driver png does not support creation and piecewise writing. Please select a format that does, such as GTiff (the default) or HFA (Erdas Imag ine)" –  GeorgeC Oct 23 '12 at 14:38
2  
Use vrt as an intermediate, "-of vrt" then use gdal_translate to convert to a png, "-of png" –  kyle Oct 25 '12 at 21:42
add comment

Take a look at the trac version of the documentation on gdal_merge.py - http://trac.osgeo.org/gdal/wiki/UserDocs/GdalMerge - for an example of how to do this.

You can make a file list in advance and then read that in with the --optfile argument. My testing of this on a Mac worked if I left out the -l argument for the unix ls command (different than the example in the above link). Tested with GDAL 1.9.1.

share|improve this answer
add comment

BAND is not consistent in PNG and GTIFF. my solution Step1: convert PNG to JPG GDAL_Translate.exe -of JPEG -expand rgb YOUR_PNG_FILE YOUR_JPEG_FILE

Step: Use JPG to merge

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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