[GIS] GDAL Merge Py on ubuntu many tif tiles into one

gdalgdal-mergelinuxpythonUbuntu

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

Best Answer

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.