17

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.

4
  • 2
    Please write the full command you used and provide more details about the results obtained using that command. Commented Mar 2, 2017 at 16:18
  • ...also quote the error message Commented Mar 2, 2017 at 16:25
  • What tool? gdal_merge? Commented Mar 2, 2017 at 20:28
  • Very old but the documentation shows how to do this on both linux and Windows machines: gdal.org/programs/… Commented Sep 26, 2023 at 17:32

2 Answers 2

40

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

5
  • 5
    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" ... Commented Mar 5, 2017 at 11:17
  • Does the same command work for Linux? Commented May 6, 2019 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? Commented Feb 13, 2020 at 9:56
  • @wondim the same command works across all platforms Commented May 4, 2020 at 11:34
  • Here is how the same thing can be done in Python: stackoverflow.com/a/66663626/2842067 Commented Mar 23, 2023 at 16:56
3

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 os.system(command) 
1
  • 1
    Important to point out gdal_merge loads all tiffs in memory, so probably wouldn't be a great choice while working with big rasters Commented May 10, 2020 at 7:04

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.