I would like to use GDAL (under Windows; OSGeo4W Shell) to merge all GeoTIFFs from one directory into a new GeoTIFF. I have tried to address them by writing c:\data\....\*.tif which however does not seem to work, using the Windows environment.

I am looking for the most practicable way to perform this operation; if possible completely within the OSGeo4W Shell. Addressing every single mosaic part name 'by hand' in the Shell is not an option.

  • 2
    Please write the full command you used and provide more details about the results obtained using that command. – Techie_Gus Mar 2 '17 at 16:18
  • ...also quote the error message – MappaGnosis Mar 2 '17 at 16:25
  • What tool? gdal_merge? – Mike T Mar 2 '17 at 20:28

You could create a virtual mosaic from all Tiff files:

gdalbuildvrt mosaic.vrt c:\data\....\*.tif

and convert it afterwards:

gdal_translate -of GTiff -co "COMPRESS=JPEG" -co "PHOTOMETRIC=YCBCR" -co "TILED=YES" mosaic.vrt mosaic.tif

Keep an eye on all the GDAL creation parameters to compress your mosaic and use gdaladdo to add overviews.

More info here: GeoTiff Compression for Dummies - Paul Ramsey

  • 3
    Just a small hint: increasing GDAL_CACHEMAX could bring a performance boost. On Windows: set GDAL_CACHE_MAX=128 or gdal_translate --config GDAL_CACHE_MAX 128 -co "COMPRESS=JPEG" ... – christoph Mar 5 '17 at 11:17
  • Does the same command work for Linux? – wondim May 6 '19 at 18:49
  • E:\>gdal_translate -a_srs EPSG:4326 -of GTiff output.vrt mosaic10.tif Input file size is 2818, 1267 0Warning 6: GDAL_RASTERIO_RESAMPLING = {nearest} not supported Warning 6: GDAL_RASTERIO_RESAMPLING = {nearest} not supported ERROR 4: E:\GHRC\20200203\202003401_20200203040951_20200203104318_20200203115400_frames\FRAME0001.tif: No such file or directory I am getting error like this. How to fix it? – Gokul Anand Feb 13 '20 at 9:56
  • @wondim the same command works across all platforms – shubhamgoel27 May 4 '20 at 11:34

If you are willing to use python, then you can use wildcards to select files with the glob module, and then you can execute the command with os.system.

import glob
import os

file_list = glob.glob("c:\data\....\*.tif")

files_string = " ".join(file_list)

command = "gdal_merge.py -o output.tif -of gtiff " + files_string

  • Important to point out gdal_merge loads all tiffs in memory, so probably wouldn't be a great choice while working with big rasters – shubhamgoel27 May 10 '20 at 7:04

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.