1

I have a problem merging raster data sets in QGIS, and I have searched various forums, but have not found a solution yet. An "ordinary" merge, for example merging the raster files

height_tile1_average.tif, height_tile2_average.tif, height_tile3_average.tif

that are all within one folder works fine.

But, in the folder there are different tifs, such like

a) height_tile1_average.tif, height_tile2_average.tif,

b) height_tile1_maximum.tif "height_tile2_maximum.tif

So is there an option to merge only the a) *average.tif"-files, and after that only the b) *maximum.tif"-files using a wildcard?

1

Quite easy with command line gdalbuildvrt http://www.gdal.org/gdalbuildvrt.html and gdal_translate http://www.gdal.org/gdal_translate.html.

gdalbuildvrt average.vrt *average*.tif

gdal_translate of GTiff -co tiled=yes average.vrt average_mosaic.tif
  • +1, a lot easier than what I wrote in my post! =) – Joseph Mar 19 '15 at 14:28
  • I just continued my raster processing. It works really fine! Thanks a lot! – André Große-Stoltenberg Apr 13 '15 at 11:40
0

You can copy the following script to your QGIS (Processing Toolbox > Scripts > Tools > Create new script).

This script takes rasters from a single folder called "Test" on the Desktop and merges all "...average.tif" files and all "...maximum.tif" files. It then places the output rasters into the "Results" subfolder:

##Merge_Rasters=name

import os, glob

from os.path import expanduser
home = expanduser("~")

path_dir = home + "\Desktop\Test\\"
path_res = path_dir + "Results\\"
#Create these folders or change the paths to fit your directories

os.chdir(path_dir)    #Sets current directory
average_input = glob.glob('*average.tif')    #classifies all files ending with "average.tif"
maximum_input = glob.glob('*maximum.tif')    #classifies all files ending with "maximum.tif"

for fname in average_input:
    processing.runalg("gdalogr:merge", ";".join(average_input) , False, False, path_res  + '/' + 'Average Result.tif')

for fname in maximum_input:
    processing.runalg("gdalogr:merge", ";".join(maximum_input) , False, False, path_res  + '/' + 'Maximum Result.tif')

You can change the script to fit your needs such as the location of the rasters, the options for the merge function etc.

Hope this helps!

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.