In my plugin I would like to use the gdal tool "cliprasterbymask" and add the new clipped raster to my project.

According to the Documentation the output has the type "raster". So it returns a raster object.

Thus, I have tried the following:

 clip = processing.run('gdal:cliprasterbymasklayer',{'INPUT': wasserstand,'MASK': gebeude,
                   'NODATA': -1, 'ALPHA_BAND': False, 'CROP_TO_CUTLINE': True, 'KEEP_RESOLUTION': True,
                   'OPTIONS': "", 'DATA_TYPE': 5, 'OUTPUT': outFile})


Unfortunately, I get the following error message which I don't know what it means.

TypeError: QgisInterface.addRasterLayer(): arguments did not match any overloaded call: overload 1: argument 1 has unexpected type 'dict' overload 2: argument 1 has unexpected type 'dict'

How do I get the outputraster from cliprasterbymasklayer and what is actually output?

Apparently, its not just a simple raster layer.

  • Please always provide errors as formatted text rather than pictures.
    – PolyGeo
    Commented Dec 2, 2019 at 20:07
  • 3
    You have to access the OUTPUT element of the dictionary returned by the processing algorithm. Assuming your outFile is a file path, the following should work: self.iface.addRasterLayer(clip['OUTPUT'], 'Clipped_raster')
    – Ben W
    Commented Dec 3, 2019 at 3:14

2 Answers 2


The result of processing.run is always a Python dictionnary. From QGIS documentation (end of the paragraph):

The run method returns a dictionary with one or more output names (the ones shown in the algorithm description) as keys and the file paths of those outputs as values

For most processing algorithm, it contains only an 'OUTPUT' key.

When you call

clip = processing.run('gdal:cliprasterbymasklayer', {
                        'MASK': my_mask_layer,

You get a dictionnary:

>>> clip
{'OUTPUT': 'C:/Temp/my_output.tif'}

So you in your case, you can either call




I'm curious to know what you "wasserstand" and "gebeude" variables are. Apparently one of these is a dictionary object instead of raster or vector as explained in the documentation. The output should be another raster layer that's clipped by the second parameter.

  • hmmm they are regular .shp and Geotiff files
    – DGIS
    Commented Dec 2, 2019 at 22:08
  • upon further inspection, I noticed you're using curly braces ({...}) which defines a "dict" in python. However, the documentation has these parameters delimited by comma only
    – amadbear
    Commented Dec 2, 2019 at 23:08

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.