Skip to content

Commit

Permalink
[processing] use a vector feature source for gdal clip raster by mask (
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Oct 12, 2017
1 parent 5b74bdf commit edf7346
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions python/plugins/processing/algs/gdal/ClipRasterByMask.py
Expand Up @@ -32,7 +32,7 @@
from qgis.core import (QgsRasterFileWriter,
QgsProcessing,
QgsProcessingParameterDefinition,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterEnum,
QgsProcessingParameterString,
Expand Down Expand Up @@ -65,9 +65,9 @@ def __init__(self):
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
self.tr('Input layer')))
self.addParameter(QgsProcessingParameterVectorLayer(self.MASK,
self.tr('Mask layer'),
[QgsProcessing.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterFeatureSource(self.MASK,
self.tr('Mask layer'),
[QgsProcessing.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterNumber(self.NODATA,
self.tr('Assign a specified nodata value to output bands'),
type=QgsProcessingParameterNumber.Double,
Expand Down Expand Up @@ -119,8 +119,7 @@ def group(self):
def getConsoleCommands(self, parameters, context, feedback):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)

maskLayer = self.parameterAsVectorLayer(parameters, self.MASK, context)
connectionString = GdalUtils.ogrConnectionString(maskLayer.source(), context)
maskLayer, maskLayerName = self.getOgrCompatibleSource(self.MASK, parameters, context, feedback)

nodata = self.parameterAsDouble(parameters, self.NODATA, context)
options = self.parameterAsString(parameters, self.OPTIONS, context)
Expand All @@ -140,10 +139,7 @@ def getConsoleCommands(self, parameters, context, feedback):
arguments.append('-tap')

arguments.append('-cutline')
arguments.append(connectionString)
if maskLayer.subsetString():
arguments.append('-cwhere')
arguments.append(maskLayer.subsetString())
arguments.append(maskLayer)

if self.parameterAsBool(parameters, self.CROP_TO_CUTLINE, context):
arguments.append('-crop_to_cutline')
Expand Down

0 comments on commit edf7346

Please sign in to comment.