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.
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]
https://docs.qgis.org/2.8/en/docs/user_manual/processing_algs/qgis/vector_overlay_tools.html
To clip a raster by vector see:
-
I knew it was something silly... many thanks indeed for your time and excellent links.Tom Dowling– Tom Dowling2017年06月07日 15:52:23 +00:00Commented Jun 7, 2017 at 15:52
-
However, I am still failing to pass the selected polygon to the now correct clip algorithm sorry.Tom Dowling– Tom Dowling2017年06月07日 17:10:03 +00:00Commented 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.Tom Dowling– Tom Dowling2017年06月08日 14:54:32 +00:00Commented Jun 8, 2017 at 14:54