32
32
33
33
from osgeo import gdal
34
34
35
- from processing .core .parameters import ParameterRaster
36
- from processing .core .parameters import ParameterVector
37
- from processing .core .parameters import ParameterBoolean
38
- from processing .core .parameters import ParameterString
39
- from processing .core .parameters import ParameterSelection
40
- from processing .core .parameters import ParameterNumber
35
+ from processing .core .parameters import (ParameterRaster ,
36
+ ParameterVector ,
37
+ ParameterBoolean ,
38
+ ParameterString ,
39
+ ParameterSelection )
41
40
42
41
from processing .core .outputs import OutputRaster
43
42
@@ -59,64 +58,39 @@ class ClipByMask(GdalAlgorithm):
59
58
ALPHA_BAND = 'ALPHA_BAND'
60
59
CROP_TO_CUTLINE = 'CROP_TO_CUTLINE'
61
60
KEEP_RESOLUTION = 'KEEP_RESOLUTION'
62
- EXTRA = 'EXTRA '
61
+ OPTIONS = 'OPTIONS '
63
62
RTYPE = 'RTYPE'
64
63
TYPE = ['Byte' , 'Int16' , 'UInt16' , 'UInt32' , 'Int32' , 'Float32' , 'Float64' ]
65
- TILED = 'TILED'
66
- COMPRESS = 'COMPRESS'
67
- JPEGCOMPRESSION = 'JPEGCOMPRESSION'
68
- PREDICTOR = 'PREDICTOR'
69
- ZLEVEL = 'ZLEVEL'
70
- BIGTIFF = 'BIGTIFF'
71
- BIGTIFFTYPE = ['' , 'YES' , 'NO' , 'IF_NEEDED' , 'IF_SAFER' ]
72
- COMPRESSTYPE = ['NONE' , 'JPEG' , 'LZW' , 'PACKBITS' , 'DEFLATE' ]
73
- TFW = 'TFW'
74
64
75
65
def getIcon (self ):
76
66
return QIcon (os .path .join (pluginPath , 'images' , 'gdaltools' , 'raster-clip.png' ))
77
67
78
68
def defineCharacteristics (self ):
79
69
self .name , self .i18n_name = self .trAlgorithm ('Clip raster by mask layer' )
80
70
self .group , self .i18n_group = self .trAlgorithm ('[GDAL] Extraction' )
71
+
81
72
self .addParameter (ParameterRaster (self .INPUT , self .tr ('Input layer' ), False ))
82
73
self .addParameter (ParameterVector (self .MASK , self .tr ('Mask layer' ),
83
74
[dataobjects .TYPE_VECTOR_POLYGON ]))
84
75
self .addParameter (ParameterString (self .NO_DATA ,
85
76
self .tr ("Nodata value, leave blank to take the nodata value from input" ),
86
77
'' , optional = True ))
87
78
self .addParameter (ParameterBoolean (self .ALPHA_BAND ,
88
- self .tr ('Create and output alpha band' ), False ))
79
+ self .tr ('Create and output alpha band' ),
80
+ False ))
89
81
self .addParameter (ParameterBoolean (self .CROP_TO_CUTLINE ,
90
- self .tr ('Crop the extent of the target dataset to the extent of the cutline' ), True ))
82
+ self .tr ('Crop the extent of the target dataset to the extent of the cutline' ),
83
+ True ))
91
84
self .addParameter (ParameterBoolean (self .KEEP_RESOLUTION ,
92
- self .tr ('Keep resolution of output raster' ), False ))
93
-
94
- params = []
95
- params .append (ParameterSelection (self .RTYPE ,
96
- self .tr ('Output raster type' ), self .TYPE , 5 ))
97
- params .append (ParameterSelection (self .COMPRESS ,
98
- self .tr ('GeoTIFF options. Compression type:' ), self .COMPRESSTYPE , 4 ))
99
- params .append (ParameterNumber (self .JPEGCOMPRESSION ,
100
- self .tr ('Set the JPEG compression level' ),
101
- 1 , 100 , 75 ))
102
- params .append (ParameterNumber (self .ZLEVEL ,
103
- self .tr ('Set the DEFLATE compression level' ),
104
- 1 , 9 , 6 ))
105
- params .append (ParameterNumber (self .PREDICTOR ,
106
- self .tr ('Set the predictor for LZW or DEFLATE compression' ),
107
- 1 , 3 , 1 ))
108
- params .append (ParameterBoolean (self .TILED ,
109
- self .tr ('Create tiled output (only used for the GTiff format)' ), False ))
110
- params .append (ParameterSelection (self .BIGTIFF ,
111
- self .tr ('Control whether the created file is a BigTIFF or a classic TIFF' ), self .BIGTIFFTYPE , 0 ))
112
- params .append (ParameterBoolean (self .TFW ,
113
- self .tr ('Force the generation of an associated ESRI world file (.tfw))' ), False ))
114
- params .append (ParameterString (self .EXTRA ,
115
- self .tr ('Additional creation parameters' ), '' , optional = True ))
116
-
117
- for param in params :
118
- param .isAdvanced = True
119
- self .addParameter (param )
85
+ self .tr ('Keep resolution of output raster' ),
86
+ False ))
87
+ self .addParameter (ParameterString (self .OPTIONS ,
88
+ self .tr ('Additional creation options' ),
89
+ optional = True ,
90
+ metadata = {'widget_wrapper' : 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper' }))
91
+ self .addParameter (ParameterSelection (self .RTYPE ,
92
+ self .tr ('Output raster type' ),
93
+ self .TYPE , 5 ))
120
94
121
95
self .addOutput (OutputRaster (self .OUTPUT , self .tr ('Clipped (mask)' )))
122
96
@@ -127,21 +101,14 @@ def getConsoleCommands(self):
127
101
self .getParameterValue (self .MASK ))
128
102
ogrMask = ogrConnectionString (mask )[1 :- 1 ]
129
103
noData = self .getParameterValue (self .NO_DATA )
104
+ opts = self .getParameterValue (self .OPTIONS )
105
+
130
106
if noData is not None :
131
107
noData = str (noData )
108
+
132
109
addAlphaBand = self .getParameterValue (self .ALPHA_BAND )
133
110
cropToCutline = self .getParameterValue (self .CROP_TO_CUTLINE )
134
111
keepResolution = self .getParameterValue (self .KEEP_RESOLUTION )
135
- extra = self .getParameterValue (self .EXTRA )
136
- if extra is not None :
137
- extra = str (extra )
138
- jpegcompression = str (self .getParameterValue (self .JPEGCOMPRESSION ))
139
- predictor = str (self .getParameterValue (self .PREDICTOR ))
140
- zlevel = str (self .getParameterValue (self .ZLEVEL ))
141
- tiled = str (self .getParameterValue (self .TILED ))
142
- compress = self .COMPRESSTYPE [self .getParameterValue (self .COMPRESS )]
143
- bigtiff = self .BIGTIFFTYPE [self .getParameterValue (self .BIGTIFF )]
144
- tfw = str (self .getParameterValue (self .TFW ))
145
112
146
113
arguments = []
147
114
arguments .append ('-ot' )
@@ -174,24 +141,9 @@ def getConsoleCommands(self):
174
141
if addAlphaBand :
175
142
arguments .append ('-dstalpha' )
176
143
177
- if extra and len (extra ) > 0 :
178
- arguments .append (extra )
179
- if GdalUtils .getFormatShortNameFromFilename (out ) == "GTiff" :
180
- arguments .append ("-co COMPRESS=" + compress )
181
- if compress == 'JPEG' :
182
- arguments .append ("-co JPEG_QUALITY=" + jpegcompression )
183
- elif (compress == 'LZW' ) or (compress == 'DEFLATE' ):
184
- arguments .append ("-co PREDICTOR=" + predictor )
185
- if compress == 'DEFLATE' :
186
- arguments .append ("-co ZLEVEL=" + zlevel )
187
- if tiled == "True" :
188
- arguments .append ("-co TILED=YES" )
189
- if tfw == "True" :
190
- arguments .append ("-co TFW=YES" )
191
- if len (bigtiff ) > 0 :
192
- arguments .append ("-co BIGTIFF=" + bigtiff )
193
-
194
- arguments .append ("-wo OPTIMIZE_SIZE=TRUE" )
144
+ if opts :
145
+ arguments .append ('-co' )
146
+ arguments .append (opts )
195
147
196
148
if GdalUtils .version () in [2010000 , 2010100 ]:
197
149
arguments .append ("--config GDALWARP_IGNORE_BAD_CUTLINE YES" )
0 commit comments