4

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

None

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")

QgsMapLayerRegistry.instance().addMapLayers([ras1])
QgsMapLayerRegistry.instance().addMapLayers([ras2])

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

2 Answers 2

3

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).

4
  • 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
    Commented Apr 21, 2016 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! Commented Apr 21, 2016 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
    Commented Apr 22, 2016 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 Commented Apr 22, 2016 at 12:16
1

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")

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.