3

I've found two different ways for creating a multiband raster using python and qgis.

Both the methods produce the expected results. The dimension of the multiband raster file created with the first method is double of the dimension (in terms of byte) of the one produced with the first method.

Which method is preferable?

import os
import processing

# first method
processing.runalg("gdalogr:merge", "/path/file1.tif;/path/file2.tif;/path/file3.tif", False, True, 0, 6, "/path/fileout.tif")

# second method
cmd = "gdal_merge.py -separate -o" + " path/outfile.tif " + " /path/file1.tif " + " /path/file2.tif " + " /path/file3.tif" 
os.system(cmd)
4

Behind the scenes they are doing the same thing. But if you use the processing approach, correctly setting the gdal path is taken care of for you. By using the os.system approach you may run into issues when the gdal_merge.py command isn't available in the system path.

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.