3

I'm working on a plugin for QGIS3, and trying to clip a raster layer using a vector mask layer containing many polygons. I've been able to successfully do this using "Clip raster by mask layer" through the processing toolbox, but when I use the following code in the plugin, the output layer is simply clipped to the extent of the vector, not to the polygons within it:

processing.run("gdal:cliprasterbymasklayer",
        {'INPUT': rasterToClip,
        'MASK': vectorMask,
        'NODATA': -1,
        'ALPHA_BAND': True,
        'CROP_TO_CUTLINE': True,
        'KEEP_RESOLUTION': True,
        'OPTIONS': "",
        'DATA_TYPE': 5,
        'OUTPUT': outputFilename})

When I say "clipped to the extent of the vector", I mean the raster values outside the polygons have retained their original values - not None or NaN etc. I was expecting all of the polygons outside the polygons (but within the extent) to be nulls. There is an alpha band in the output, in which all pixels appear to be set at 255.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.