3232
3333from osgeo import gdal
3434
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 )
4140
4241from processing .core .outputs import OutputRaster
4342
@@ -59,64 +58,39 @@ class ClipByMask(GdalAlgorithm):
5958 ALPHA_BAND = 'ALPHA_BAND'
6059 CROP_TO_CUTLINE = 'CROP_TO_CUTLINE'
6160 KEEP_RESOLUTION = 'KEEP_RESOLUTION'
62- EXTRA = 'EXTRA '
61+ OPTIONS = 'OPTIONS '
6362 RTYPE = 'RTYPE'
6463 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'
7464
7565 def getIcon (self ):
7666 return QIcon (os .path .join (pluginPath , 'images' , 'gdaltools' , 'raster-clip.png' ))
7767
7868 def defineCharacteristics (self ):
7969 self .name , self .i18n_name = self .trAlgorithm ('Clip raster by mask layer' )
8070 self .group , self .i18n_group = self .trAlgorithm ('[GDAL] Extraction' )
71+
8172 self .addParameter (ParameterRaster (self .INPUT , self .tr ('Input layer' ), False ))
8273 self .addParameter (ParameterVector (self .MASK , self .tr ('Mask layer' ),
8374 [dataobjects .TYPE_VECTOR_POLYGON ]))
8475 self .addParameter (ParameterString (self .NO_DATA ,
8576 self .tr ("Nodata value, leave blank to take the nodata value from input" ),
8677 '' , optional = True ))
8778 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 ))
8981 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 ))
9184 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 ))
12094
12195 self .addOutput (OutputRaster (self .OUTPUT , self .tr ('Clipped (mask)' )))
12296
@@ -127,21 +101,14 @@ def getConsoleCommands(self):
127101 self .getParameterValue (self .MASK ))
128102 ogrMask = ogrConnectionString (mask )[1 :- 1 ]
129103 noData = self .getParameterValue (self .NO_DATA )
104+ opts = self .getParameterValue (self .OPTIONS )
105+
130106 if noData is not None :
131107 noData = str (noData )
108+
132109 addAlphaBand = self .getParameterValue (self .ALPHA_BAND )
133110 cropToCutline = self .getParameterValue (self .CROP_TO_CUTLINE )
134111 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 ))
145112
146113 arguments = []
147114 arguments .append ('-ot' )
@@ -174,24 +141,9 @@ def getConsoleCommands(self):
174141 if addAlphaBand :
175142 arguments .append ('-dstalpha' )
176143
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 )
195147
196148 if GdalUtils .version () in [2010000 , 2010100 ]:
197149 arguments .append ("--config GDALWARP_IGNORE_BAD_CUTLINE YES" )
0 commit comments