mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
Merge pull request #8445 from NaturalGIS/add_te_paramater_in_gdal_clip_by_mask
add the -te and -te_srs and -multi parameters to the gdalwarp tool used to clip rasters by mask layers
This commit is contained in:
commit
c39e2b83da
@ -34,10 +34,12 @@ from qgis.core import (QgsRasterFileWriter,
|
|||||||
QgsProcessingException,
|
QgsProcessingException,
|
||||||
QgsProcessingParameterDefinition,
|
QgsProcessingParameterDefinition,
|
||||||
QgsProcessingParameterFeatureSource,
|
QgsProcessingParameterFeatureSource,
|
||||||
|
QgsProcessingParameterCrs,
|
||||||
QgsProcessingParameterRasterLayer,
|
QgsProcessingParameterRasterLayer,
|
||||||
QgsProcessingParameterEnum,
|
QgsProcessingParameterEnum,
|
||||||
QgsProcessingParameterString,
|
QgsProcessingParameterString,
|
||||||
QgsProcessingParameterNumber,
|
QgsProcessingParameterNumber,
|
||||||
|
QgsProcessingParameterExtent,
|
||||||
QgsProcessingParameterBoolean,
|
QgsProcessingParameterBoolean,
|
||||||
QgsProcessingParameterRasterDestination)
|
QgsProcessingParameterRasterDestination)
|
||||||
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
||||||
@ -56,6 +58,9 @@ class ClipRasterByMask(GdalAlgorithm):
|
|||||||
KEEP_RESOLUTION = 'KEEP_RESOLUTION'
|
KEEP_RESOLUTION = 'KEEP_RESOLUTION'
|
||||||
OPTIONS = 'OPTIONS'
|
OPTIONS = 'OPTIONS'
|
||||||
DATA_TYPE = 'DATA_TYPE'
|
DATA_TYPE = 'DATA_TYPE'
|
||||||
|
TARGET_EXTENT = 'TARGET_EXTENT'
|
||||||
|
TARGET_EXTENT_CRS = 'TARGET_EXTENT_CRS'
|
||||||
|
MULTITHREADING = 'MULTITHREADING'
|
||||||
OUTPUT = 'OUTPUT'
|
OUTPUT = 'OUTPUT'
|
||||||
|
|
||||||
TYPES = ['Use input layer data type', 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
|
TYPES = ['Use input layer data type', 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
|
||||||
@ -84,6 +89,24 @@ class ClipRasterByMask(GdalAlgorithm):
|
|||||||
self.tr('Keep resolution of output raster'),
|
self.tr('Keep resolution of output raster'),
|
||||||
defaultValue=False))
|
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,
|
options_param = QgsProcessingParameterString(self.OPTIONS,
|
||||||
self.tr('Additional creation options'),
|
self.tr('Additional creation options'),
|
||||||
defaultValue='',
|
defaultValue='',
|
||||||
@ -164,6 +187,22 @@ class ClipRasterByMask(GdalAlgorithm):
|
|||||||
if nodata is not None:
|
if nodata is not None:
|
||||||
arguments.append('-dstnodata {}'.format(nodata))
|
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:
|
if options:
|
||||||
arguments.extend(GdalUtils.parseCreationOptions(options))
|
arguments.extend(GdalUtils.parseCreationOptions(options))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user