1

Trying to batch mosaic 1000 Gtiff rasters (all in one folder) into 1 tif file via gdal merge on linux ubuntu.

Having trouble with the linux command to bring in all files in a folder into the output tiff.

Looking for sample code for use in gdal on ubuntu in the terminal.

For Ubuntu my best guess is

for f in *.tiff; do gdal_merge -of GTiff "$f"; done
  • Have you tried anything? – John Powell Oct 9 '14 at 16:08
  • Updated Question. John Barca – If you do not know- just GIS Oct 9 '14 at 16:50
  • Answer posted. I hope that is what you wanted. You probably want to do a test with a few adjacent tiles first, as mosaicing 1000 tiles might take a while :D – John Powell Oct 9 '14 at 18:35
  • Let me know if gdalwarp $(ls *.tif) output.tif works instead, and I will update the answer. I know you asked about gdal_merge, but gdalwarp seems to be a better solution for large volumens. – John Powell Oct 10 '14 at 15:12
4
gdal_merge.py -o output.tif `ls *.tif`

The back ticks mean execute whatever is inside the back ticks before the main command, so this will find all tif files in current directory, which will then be used as the input to gdal_merge.py.

Instead of backticks, you can also use the $(command) syntax, ie,

gdal_merge.py -o output.tif $(ls *.tif)

is equivalent to the previous.

If you have more complicated search requirements, you can use the unix/linux find command first in conjunction with ls to create a list to pass to gdal_merge.

I just did this successfully with 16 tiffs on ubuntu, so it certainly should work for you.

  • it looks, I am testing. – If you do not know- just GIS Oct 9 '14 at 19:06
  • So when I run on even two tifs I get a memory error. 0...10...20...30...40...50Traceback MemoryError – If you do not know- just GIS Oct 9 '14 at 19:16
  • Perhaps use gdalwarp instead? gdal_merge copies files into memory first, whereas gdalwarp does this incrementally. Try, gdalwarp $(ls *.tif) output.tif – John Powell Oct 9 '14 at 19:22
  • Thanks, will try next week When I am on a PC. Never used warp to merge before. I assume I have to set the extents etc. manually – If you do not know- just GIS Oct 10 '14 at 21:57
  • No, all read from the world files. Literally as simple as what I posted in the comments. – John Powell Oct 10 '14 at 22:00

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.