4

I want to create a mosaic of all tif files in a directory on windows 7.

How could I create a one-line command in the windows command line to loop through all tifs and merge them all together using gdal_merge.py?

I tried this;

for %i in (*.tif) do gdal_merge.py -of GTiff %i mosaic.tif

but it gives me an error about mosaic not being a supported dataset name??

3
  • 2
    1. create list using dir /b /s *.tif > list.txt 2. then gdal_merge.py --optfile list.txt Commented Feb 28, 2014 at 12:17
  • gdal_merge.py -optfile list.txt does not work using osgeo4w (i.e., under Windows). Throws a DLL Load failed exception
    – GT.
    Commented Mar 6, 2015 at 20:24
  • According to the userdocs for gdal_merge, a script exists to kludge gdal_merge wildcards into Windows gdal, but I haven't tried it. See trac.osgeo.org/gdal/wiki/UserDocs/GdalMerge
    – GT.
    Commented Mar 6, 2015 at 20:34

2 Answers 2

4

Your command line will try to merge mosaic.tif (as part of *.tif) with itself. Creating the mosaic in another folder would prevent that.

The correct syntax for batch processing is:

for %%N in (D:\Karten\gdal\gdal2tiles\NL50\*.tif) DO gdal_translate -of vrt -expand rgba %%N D:\Karten\gdal\gdal2tiles\NL50\%%~nN.vrt
gdalbuildvrt -allow_projection_difference index.vrt NL50\*.vrt
pause

This should also work for gdal_merge.py, but I prefer to work with the vrt solution.

1

You do not need a batch for merging all the tif from a repository in a single tif file

gdal_merge.py -o out.tif *.tif
2
  • 1
    gdal_merge.py -o out.tif *.tif does not work using osgeo4w (i.e., under Windows). Throws a DLL Load failed exception
    – GT.
    Commented Mar 6, 2015 at 20:23
  • According to the userdocs for gdal_merge, a script exists to kludge gdal_merge wildcards into Windows gdal, but I haven't tried it. See trac.osgeo.org/gdal/wiki/UserDocs/GdalMerge
    – GT.
    Commented Mar 6, 2015 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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