I am using gdalogr:merge
in 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; ras2None
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
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).
-
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– Luisito9182016年04月21日 22:28:01 +00:00Commented 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!Germán Carrillo– Germán Carrillo2016年04月21日 22:49:13 +00:00Commented 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 errorLuisito918– Luisito9182016年04月22日 05:51:01 +00:00Commented 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.2Germán Carrillo– Germán Carrillo2016年04月22日 12:16:11 +00:00Commented Apr 22, 2016 at 12:16
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")