The overall aim of this is to clip a raster (rlayer), feature by feature of a shapefile (vlayer). Then run univariate stats on each clipped DEM. Passing the answer to a table for output.

However I have fallen at the first hurdle and cannot get clip to work. Example error:

Unable to execute algorithm
Wrong parameter value: <qgis._core.QgsRasterLayer object at 0x000000002455D9D8>

My code as of the moment is:

#Load the required modules
from qgis.core import*
import qgis.utils
import processing
import os

#Load administrative polygons
vlayer = (iface.addVectorLayer
if not vlayer:
    print "Vector layer failed to load!"

#Load raster for analysis
rlayer = (iface.addRasterLayer
if not rlayer:
    print "Raster layer failed to load!"

#Iteratively analyse admin polys. 
features = vlayer.getFeatures()

for feature in features:
    print "Feature ID %d: " % feature.id()
    processing.runalg('qgis:clip',rlayer, feature, None )  


I have tried variations such as naming the selected feature before passing it to the algorithm but that fails as well. Output is currently set to NONE to allow testing/pass the result to the univaraite stats alg when I get there.

I am aware this is likely a simple problem/mistake, but I am relatively new to this.

Note that I have already tried v.rast.stats from the processing toolbox, it fails to write any output to the shapefile, for reasons unknown.


1 Answer 1


The input layer and clip layer for that processing tool only clips vector data, not raster data. You are trying to clip a raster layer.

Input layer [vector: any] Clip layer [vector: any]


To clip a raster by vector see:

Clipping a raster using an irregular polygon with Python

How to clip a raster by a shapefile in pyqgis?

  • I knew it was something silly... many thanks indeed for your time and excellent links. Jun 7, 2017 at 15:52
  • However, I am still failing to pass the selected polygon to the now correct clip algorithm sorry. Jun 7, 2017 at 17:10
  • To close this question, I changed plan as still could not get clip to accept the passed/selected polygon. Therefore have split the polygons and am running stats from there. Jun 8, 2017 at 14:54

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.