1616* *
1717***************************************************************************
1818"""
19- from builtins import str
2019
2120__author__ = 'Alexander Bruy'
2221__date__ = 'October 2013'
2625
2726__revision__ = '$Format:%H$'
2827
29- from qgis .core import (QgsProcessingParameterRasterLayer ,
28+ from qgis .core import (QgsRasterFileWriter ,
29+ QgsProcessingParameterDefinition ,
30+ QgsProcessingParameterRasterLayer ,
3031 QgsProcessingParameterBand ,
3132 QgsProcessingParameterBoolean ,
3233 QgsProcessingParameterEnum ,
3334 QgsProcessingParameterFile ,
35+ QgsProcessingParameterString ,
3436 QgsProcessingParameterRasterDestination )
3537from processing .algs .gdal .GdalAlgorithm import GdalAlgorithm
3638from processing .algs .gdal .GdalUtils import GdalUtils
@@ -43,23 +45,40 @@ class ColorRelief(GdalAlgorithm):
4345 COMPUTE_EDGES = 'COMPUTE_EDGES'
4446 COLOR_TABLE = 'COLOR_TABLE'
4547 MATCH_MODE = 'MATCH_MODE'
48+ OPTIONS = 'OPTIONS'
4649 OUTPUT = 'OUTPUT'
4750
48- MATCHING_MODES = ['"0,0,0,0" RGBA' , 'Exact color' , 'Nearest color' ]
49-
5051 def __init__ (self ):
5152 super ().__init__ ()
5253
5354 def initAlgorithm (self , config = None ):
54- self .addParameter (QgsProcessingParameterRasterLayer (self .INPUT , self .tr ('Input layer' )))
55- self .addParameter (QgsProcessingParameterBand (
56- self .BAND , self .tr ('Band number' ), parentLayerParameterName = self .INPUT ))
55+ self .modes = ((self .tr ('Use strict color matching' ), '-exact_color_entry' ),
56+ (self .tr ('Use closest RGBA quadruplet' ), '-nearest_color_entry' ))
57+
58+ self .addParameter (QgsProcessingParameterRasterLayer (self .INPUT ,
59+ self .tr ('Input layer' )))
60+ self .addParameter (QgsProcessingParameterBand (self .BAND ,
61+ self .tr ('Band number' ),
62+ parentLayerParameterName = self .INPUT ))
5763 self .addParameter (QgsProcessingParameterBoolean (self .COMPUTE_EDGES ,
58- self .tr ('Compute edges' ), defaultValue = False ))
64+ self .tr ('Compute edges' ),
65+ defaultValue = False ))
5966 self .addParameter (QgsProcessingParameterFile (self .COLOR_TABLE ,
60- self .tr ('Color configuration file' ), optional = False ))
67+ self .tr ('Color configuration file' )))
6168 self .addParameter (QgsProcessingParameterEnum (self .MATCH_MODE ,
62- self .tr ('Matching mode' ), options = self .MATCHING_MODES , defaultValue = 0 ))
69+ self .tr ('Matching mode' ),
70+ options = [i [0 ] for i in self .modes ],
71+ defaultValue = 0 ))
72+ options_param = QgsProcessingParameterString (self .OPTIONS ,
73+ self .tr ('Additional creation parameters' ),
74+ defaultValue = '' ,
75+ optional = True )
76+
77+ options_param .setFlags (options_param .flags () | QgsProcessingParameterDefinition .FlagAdvanced )
78+ options_param .setMetadata ({
79+ 'widget_wrapper' : {
80+ 'class' : 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper' }})
81+ self .addParameter (options_param )
6382
6483 self .addParameter (QgsProcessingParameterRasterDestination (self .OUTPUT , self .tr ('Color relief' )))
6584
@@ -77,23 +96,19 @@ def getConsoleCommands(self, parameters, context, feedback):
7796 inLayer = self .parameterAsRasterLayer (parameters , self .INPUT , context )
7897 arguments .append (inLayer .source ())
7998 arguments .append (self .parameterAsFile (parameters , self .COLOR_TABLE , context ))
80- #filePath = unicode(self.getParameterValue(self.COLOR_TABLE))
81- #if filePath is None or filePath == '':
82- # filePath = os.path.join(os.path.dirname(__file__), 'terrain.txt')
83- #arguments.append(filePath)
99+
84100 out = self .parameterAsOutputLayer (parameters , self .OUTPUT , context )
85101 arguments .append (out )
86102
103+ arguments .append ('-of' )
104+ arguments .append (QgsRasterFileWriter .driverForExtension (os .path .splitext (out )[1 ]))
105+
87106 arguments .append ('-b' )
88107 arguments .append (str (self .parameterAsInt (parameters , self .BAND , context )))
89108
90109 if self .parameterAsBool (parameters , self .COMPUTE_EDGES , context ):
91110 arguments .append ('-compute_edges' )
92111
93- mode = self .parameterAsEnum (parameters , self .MATCH_MODE , context )
94- if mode == 1 :
95- arguments .append ('-exact_color_entry' )
96- elif mode == 2 :
97- arguments .append ('-nearest_color_entry' )
112+ arguments .append (self .modes [self .parameterAsEnum (parameters , self .MATCH_MODE , context )][1 ])
98113
99114 return ['gdaldem' , GdalUtils .escapeAndJoin (arguments )]
0 commit comments