I want to clip a raster (GeoTIFF) using a polygon shapefile. Both are in the same reference system. The polygon is not a regular polygon but has many vertices.
I used this Python script below in QGIS 2.18.4
import processing
processing.runandload("gdalogr:cliprasterbymasklayer", \
"/home/giacomo/Desktop/RSM/bordi.tif", \
"/home/giacomo/Desktop/RSM/mask_vec.shp", \
"none", \
False, \
True, \
True, \
"", \
"", \
0, \
0, \
0, \
False, \
"", \
False, \
"", \
"/home/giacomo/Desktop/RSM/bordi_clip.tif")
But I get Error: Wrong parameter value:
The parameters required as input are
INPUT <ParameterRaster>
MASK <ParameterVector>
NO_DATA <ParameterString>
ALPHA_BAND <ParameterBoolean>
CROP_TO_CUTLINE <ParameterBoolean>
KEEP_RESOLUTION <ParameterBoolean>
RTYPE <ParameterSelection>
COMPRESS <ParameterSelection>
JPEGCOMPRESSION <ParameterNumber>
ZLEVEL <ParameterNumber>
PREDICTOR <ParameterNumber>
TILED <ParameterBoolean>
BIGTIFF <ParameterSelection>
TFW <ParameterBoolean>
EXTRA <ParameterString>
OUTPUT <OutputRaster>
Best Answer
There are several errors in your code.
Firstly, you need to specify your input layers as objects (and not as strings):
Then, you didn't specify the
RTYPE
parameter:You can't set
""
as value (as you did), but a number is required.The same with the
COMPRESS
parameter:You can't set
""
as value (as you did), but a number is required.Therefore, you set
0
as value forJPEGCOMPRESSION
,ZLEVEL
andPREDICTOR
parameters. They can't be equal to 0 so, if you don't know what they mean, leave the default values (i.e.75
,6
and1
, respectively).Then, you didn't specify the
BIGTIFF
parameter:Finally, you can't set
""
as value, but a number is required.A working solution for you should be this: