Skip to content
Permalink
Browse files

Merge pull request #8445 from NaturalGIS/add_te_paramater_in_gdal_cli…

…p_by_mask

add the -te and -te_srs and -multi parameters to the gdalwarp tool used to clip rasters by mask layers
  • Loading branch information
luipir committed Dec 4, 2018
2 parents d4c62d1 + 3165382 commit c39e2b83da47e7cb88319f77c9461f9a98a46c28
Showing with 39 additions and 0 deletions.
  1. +39 −0 python/plugins/processing/algs/gdal/ClipRasterByMask.py
@@ -34,10 +34,12 @@
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterCrs,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterEnum,
QgsProcessingParameterString,
QgsProcessingParameterNumber,
QgsProcessingParameterExtent,
QgsProcessingParameterBoolean,
QgsProcessingParameterRasterDestination)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
@@ -56,6 +58,9 @@ class ClipRasterByMask(GdalAlgorithm):
KEEP_RESOLUTION = 'KEEP_RESOLUTION'
OPTIONS = 'OPTIONS'
DATA_TYPE = 'DATA_TYPE'
TARGET_EXTENT = 'TARGET_EXTENT'
TARGET_EXTENT_CRS = 'TARGET_EXTENT_CRS'
MULTITHREADING = 'MULTITHREADING'
OUTPUT = 'OUTPUT'

TYPES = ['Use input layer data type', 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
@@ -84,6 +89,24 @@ def initAlgorithm(self, config=None):
self.tr('Keep resolution of output raster'),
defaultValue=False))

target_extent_param = QgsProcessingParameterExtent(self.TARGET_EXTENT,
self.tr('Georeferenced extents of output file to be created'),
optional=True)
target_extent_param.setFlags(target_extent_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(target_extent_param)

target_extent_crs_param = QgsProcessingParameterCrs(self.TARGET_EXTENT_CRS,
self.tr('CRS of the target raster extent'),
optional=True)
target_extent_crs_param.setFlags(target_extent_crs_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(target_extent_crs_param)

multithreading_param = QgsProcessingParameterBoolean(self.MULTITHREADING,
self.tr('Use multithreaded warping implementation'),
defaultValue=False)
multithreading_param.setFlags(multithreading_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(multithreading_param)

options_param = QgsProcessingParameterString(self.OPTIONS,
self.tr('Additional creation options'),
defaultValue='',
@@ -164,6 +187,22 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if nodata is not None:
arguments.append('-dstnodata {}'.format(nodata))

extent = self.parameterAsExtent(parameters, self.TARGET_EXTENT, context)
if not extent.isNull():
arguments.append('-te')
arguments.append(extent.xMinimum())
arguments.append(extent.yMinimum())
arguments.append(extent.xMaximum())
arguments.append(extent.yMaximum())

extentCrs = self.parameterAsCrs(parameters, self.TARGET_EXTENT_CRS, context)
if extentCrs:
arguments.append('-te_srs')
arguments.append(extentCrs.authid())

if self.parameterAsBool(parameters, self.MULTITHREADING, context):
arguments.append('-multi')

if options:
arguments.extend(GdalUtils.parseCreationOptions(options))

0 comments on commit c39e2b8

Please sign in to comment.
You can’t perform that action at this time.