I am using gdalogr:mergein Python console in order to merge to rasters (.tif) But I don't really understand the first parameter, where I have to put two variables.

I get the following error:

Unable to execute algorithm
Wrong parameter value: ras1; ras2


import processing   
from processing.core.Processing import Processing
from qgis.core import *
from qgis.gui import *

ras1 =QgsRasterLayer("H:/pyQGIS/DATA_U6/mdt_483.tif","MDT483")
ras2 = QgsRasterLayer("H:/pyQGIS/DATA_U6/mdt_508.tif", "MDT508")


merj = processing.runalg("gdalogr:merge",'ras1; ras2', False, False, 4,"H:/pyQGIS/DATA_U6/mdt_mosaico.tif")

Hmm @GermánCarrillo's solution also worked for me. If you want to use ras1 and ras2 as input parameters then you can try the following:

import processing

ras1 = "H:/pyQGIS/DATA_U6/mdt_483.tif"
ras2 = "H:/pyQGIS/DATA_U6/mdt_508.tif"

merj = processing.runalg("gdalogr:merge", ras1 + ";" + ras2, False, False, 4,"H:/pyQGIS/DATA_U6/mdt_mosaico.tif")
| improve this answer | |

The algorithm expects (in the first argument) the input raster paths using a semicolon as separator. Don't add any blank space after the semicolon.

Your script could be just 2 lines long now:

import processing

merj = processing.runalg('gdalogr:merge','H:/pyQGIS/DATA_U6/mdt_483.tif;H:/pyQGIS/DATA_U6/mdt_508.tif', False, False, 4,'H:/pyQGIS/DATA_U6/mdt_mosaico.tif')

It should do the trick. I've tested it with Processing versions 2.10.3 and 2.12.2 on QGIS 2.14.1 (Essen).

| improve this answer | |
  • This is not working, that is why It is so extrange, according to the documentation, this should work . My QGIS version is 2.14 (Essen) – Luisito918 Apr 21 '16 at 22:28
  • What version of Processing are you using? On my GNU/Linux machine, using QGIS 2.14.1 and Processing 2.10.3, it worked! – Germán Carrillo Apr 21 '16 at 22:49
  • It is 2.14 (Essen),The version of my Processing is 2.12.2. I tried to change spaces from the ";" but still get nothing..The same error – Luisito918 Apr 22 '16 at 5:51
  • Just copy & paste the line I included in my answer. No need to change anything else. I'll have a look with Processing 2.12.2 – Germán Carrillo Apr 22 '16 at 12:16

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.