In my PyQGIS standalone script I want to use the SAGA Tool "Clip raster by mask layer". I have tried to following.
def clipRaster(self):
raster = self.getRasterLayer()
vector = self.getVectorLayer()
outDir = os.path.join(QgsProject().instance().homePath(), "clip.tiff")
param = {"input": raster,
"polygons": vector,
"output": outDir,
}
clip = processing.run('saga:cliprasterwithpolygon', param)
rlayer = QgsRasterLayer(clip['output'], 'clip')
QgsProject().instance().addMapLayer(rlayer)
Unfortunately, I get the following error message:
_core.QgsProcessingException: Unable to execute algorithm Could not load source layer for INPUT: no value specified for parameter Traceback (most recent call last): File "C:/Users/Jan/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gebeude_betroffenheit\Gebeude_Betroffenheit.py", line 292, in run self.clipRaster() File "C:/Users/Jan/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gebeude_betroffenheit\Gebeude_Betroffenheit.py", line 237, in clipRaster clip = processing.run('saga:cliprasterwithpolygon', 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 Could not load source layer for INPUT: no value specified for Parameter
Hmm it indicates that there is something wrong with the raster layer but the same layer works perfectly fine for another function. Thus, I believe there is something wrong with the "param" variable...
Does anyone see the problem in my code?
I'm using QGIS 3.4