4

In my standalone PyQGIS script I would like to merge two raster layer. "zero" and "raster". Both variables are definitly QgsRasterLayer objects. This is the function:

def merge(self):
    zero = self.setToZero()
    raster = self.getRasterLayer()
    outDir = os.path.join(QgsProject().instance().homePath(), "Verschmelzung.tiff")
    param = {"input": [zero, raster],
             "output": outDir}
    merge = processing.run('gdal:merge', param)
    rlayer = QgsRasterLayer(merge['output'], 'mergedRaster')
    return rlayer

An that is the error message:

_core.QgsProcessingException: Unable to execute algorithm Incorrect parameter value for INPUT  Traceback (most recent call last):   File "C:/Users/Jan/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gebeude_betroffenheit\Gebeude_Betroffenheit.py", line 347, in run
    self.zonalStatistics()   File "C:/Users/Jan/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gebeude_betroffenheit\Gebeude_Betroffenheit.py", line 315, in zonalStatistics
    raster = self.focalStatistics()   File "C:/Users/Jan/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gebeude_betroffenheit\Gebeude_Betroffenheit.py", line 297, in focalStatistics
    raster = self.merge()   File "C:/Users/Jan/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gebeude_betroffenheit\Gebeude_Betroffenheit.py", line 292, in merge
    merge = processing.run('gdal:merge', param)   File "C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python/plugins\processing\tools\general.py", line 105, in run
    return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)   File "C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python/plugins\processing\core\Processing.py", line 139, in runAlgorithm
    raise QgsProcessingException(msg)
_core.QgsProcessingException:
    Unable to execute algorithm Incorrect parameter value for INPUT

According to this link it wants a list of rasters, and that is what I'm giving no.

I don't see the problem…

I'm using QGIS 3.4

1 Answer 1

7

All letters of keys (input, output etc.) in params have to contain just capital letters.

Your script will work, if you convert {"input": [zero, raster], "output": outDir} into {"INPUT": [zero, raster], "OUTPUT": outDir}. At least, you don't encounter that error.

1
  • OK I see, yes you are right, now it works for me. What's interesting is that I'm also using a grass and regular QGIS processing tools and with them I don't have to capitalize the parameter keys. It seems gdal is more sensitive than the others.
    – DGIS
    Apr 1, 2020 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.