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 ("C:/Users/geol-tdi/Documents/UK_NUTS.shp", "nutspoly", "ogr")) if not vlayer: print "Vector layer failed to load!" #Load raster for analysis rlayer = (iface.addRasterLayer ("C:/Users/geol-tdi/Documents/Rasters/UKwheatPEC80div50.tif", "WheatD")) if not rlayer: print "Raster layer failed to load!" #Iteratively analyse admin polys. vlayer.selectAll() features = vlayer.getFeatures() for feature in features: vlayer.setSelectedFeatures([feature.id()]) print "Feature ID %d: " % feature.id() processing.runalg('qgis:clip',rlayer, feature, None ) vlayer.removeSelection() vlayer.removeSelection()
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.