[GIS] How to batch merge rasters using FOSSGIS tools

gdal-mergegrassmergeqgisraster

I'm working with QGIS 1.8 (gdal 1.9.2) and GRASS 6.4.3…but on Windows 7.

I "just" want to merge my raster.

I've got a folder with 50 GTiff raster from Lidar data.

The aim is to merge raster before or after an import into GRASS in order to do some contours…

Before GRASS, I tried gdal_merge with QGIS's gui, without any option. I had an error message : "permission denied".

So I tried it in GRASS with r.patch but :
First the gui don't allows you to select multiple raster at one time…

Then I don't know how to batch with GRASS functions in Windows…I tried the GRASS command line but can't locate in the current mapset (didn't understand how). When I had the windows installer for QGIS, this commandline putted you in the current mapset but it's not the case with the basic installation of QGIS.

I'm quite locked…Any help ?

Best Answer

  • Open MSYS (It should have been downloaded along if you used OSGeo4W utility to install qgis)
  • cd (Change Directory) to your folder with your data.
    • cd c:/(path to)/(my data)/ (Hint: pressing tab, autocompletes)
  • one-line it: gdal_merge.py -o out.tif $(ls *.tif)
    • out.tif -> is your output file, name it to whatever you want.
    • $(ls *.tif) -> lists all the files ending with tif, and parses it at a parameter to gdal_merge. Change it as needed.

you can explore more options of gdal_merge.py at the relevant page.