34
34
QgsProcessingException ,
35
35
QgsProcessingParameterDefinition ,
36
36
QgsProcessingParameterFeatureSource ,
37
+ QgsProcessingParameterCrs ,
37
38
QgsProcessingParameterRasterLayer ,
38
39
QgsProcessingParameterEnum ,
39
40
QgsProcessingParameterString ,
40
41
QgsProcessingParameterNumber ,
42
+ QgsProcessingParameterExtent ,
41
43
QgsProcessingParameterBoolean ,
42
44
QgsProcessingParameterRasterDestination )
43
45
from processing .algs .gdal .GdalAlgorithm import GdalAlgorithm
@@ -56,6 +58,9 @@ class ClipRasterByMask(GdalAlgorithm):
56
58
KEEP_RESOLUTION = 'KEEP_RESOLUTION'
57
59
OPTIONS = 'OPTIONS'
58
60
DATA_TYPE = 'DATA_TYPE'
61
+ TARGET_EXTENT = 'TARGET_EXTENT'
62
+ TARGET_EXTENT_CRS = 'TARGET_EXTENT_CRS'
63
+ MULTITHREADING = 'MULTITHREADING'
59
64
OUTPUT = 'OUTPUT'
60
65
61
66
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):
84
89
self .tr ('Keep resolution of output raster' ),
85
90
defaultValue = False ))
86
91
92
+ target_extent_param = QgsProcessingParameterExtent (self .TARGET_EXTENT ,
93
+ self .tr ('Georeferenced extents of output file to be created' ),
94
+ optional = True )
95
+ target_extent_param .setFlags (target_extent_param .flags () | QgsProcessingParameterDefinition .FlagAdvanced )
96
+ self .addParameter (target_extent_param )
97
+
98
+ target_extent_crs_param = QgsProcessingParameterCrs (self .TARGET_EXTENT_CRS ,
99
+ self .tr ('CRS of the target raster extent' ),
100
+ optional = True )
101
+ target_extent_crs_param .setFlags (target_extent_crs_param .flags () | QgsProcessingParameterDefinition .FlagAdvanced )
102
+ self .addParameter (target_extent_crs_param )
103
+
104
+ multithreading_param = QgsProcessingParameterBoolean (self .MULTITHREADING ,
105
+ self .tr ('Use multithreaded warping implementation' ),
106
+ defaultValue = False )
107
+ multithreading_param .setFlags (multithreading_param .flags () | QgsProcessingParameterDefinition .FlagAdvanced )
108
+ self .addParameter (multithreading_param )
109
+
87
110
options_param = QgsProcessingParameterString (self .OPTIONS ,
88
111
self .tr ('Additional creation options' ),
89
112
defaultValue = '' ,
@@ -164,6 +187,22 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
164
187
if nodata is not None :
165
188
arguments .append ('-dstnodata {}' .format (nodata ))
166
189
190
+ extent = self .parameterAsExtent (parameters , self .TARGET_EXTENT , context )
191
+ if not extent .isNull ():
192
+ arguments .append ('-te' )
193
+ arguments .append (extent .xMinimum ())
194
+ arguments .append (extent .yMinimum ())
195
+ arguments .append (extent .xMaximum ())
196
+ arguments .append (extent .yMaximum ())
197
+
198
+ extentCrs = self .parameterAsCrs (parameters , self .TARGET_EXTENT_CRS , context )
199
+ if extentCrs :
200
+ arguments .append ('-te_srs' )
201
+ arguments .append (extentCrs .authid ())
202
+
203
+ if self .parameterAsBool (parameters , self .MULTITHREADING , context ):
204
+ arguments .append ('-multi' )
205
+
167
206
if options :
168
207
arguments .extend (GdalUtils .parseCreationOptions (options ))
169
208
0 commit comments