29
29
30
30
from qgis .PyQt .QtGui import QIcon
31
31
32
+ from qgis .core import (QgsProcessingParameterRasterLayer ,
33
+ QgsProcessingParameterEnum ,
34
+ QgsProcessingParameterString ,
35
+ QgsProcessingParameterBoolean ,
36
+ QgsProcessingOutputRasterLayer )
32
37
from processing .algs .gdal .GdalAlgorithm import GdalAlgorithm
33
- from processing .core .parameters import ParameterRaster
34
- from processing .core .parameters import ParameterBoolean
35
- from processing .core .parameters import ParameterSelection
36
- from processing .core .parameters import ParameterString
37
- from processing .core .outputs import OutputRaster
38
-
39
38
from processing .algs .gdal .GdalUtils import GdalUtils
40
39
41
40
pluginPath = os .path .split (os .path .split (os .path .dirname (__file__ ))[0 ])[0 ]
@@ -46,41 +45,50 @@ class gdaladdo(GdalAlgorithm):
46
45
INPUT = 'INPUT'
47
46
LEVELS = 'LEVELS'
48
47
CLEAN = 'CLEAN'
49
- RESAMPLING_METHOD = 'RESAMPLING_METHOD '
48
+ RESAMPLING = 'RESAMPLING '
50
49
FORMAT = 'FORMAT'
51
50
OUTPUT = 'OUTPUT'
52
51
53
- METHODS = [
54
- 'nearest' ,
55
- 'average' ,
56
- 'gauss' ,
57
- 'cubic' ,
58
- 'average_mp' ,
59
- 'average_magphase' ,
60
- 'mode' ,
61
- ]
62
-
63
- FORMATS = ['Internal (if possible)' , 'External (GTiff .ovr)' ,
64
- 'External (ERDAS Imagine .aux)' ]
65
-
66
- def icon (self ):
67
- return QIcon (os .path .join (pluginPath , 'images' , 'gdaltools' , 'raster-overview.png' ))
68
-
69
52
def __init__ (self ):
70
53
super ().__init__ ()
71
54
72
55
def initAlgorithm (self , config = None ):
73
- self .addParameter (ParameterRaster (
74
- self .INPUT , self .tr ('Input layer' ), False ))
75
- self .addParameter (ParameterString (self .LEVELS ,
76
- self .tr ('Overview levels' ), '2 4 8 16' ))
77
- self .addParameter (ParameterBoolean (self .CLEAN ,
78
- self .tr ('Remove all existing overviews' ), False ))
79
- self .addParameter (ParameterSelection (self .RESAMPLING_METHOD ,
80
- self .tr ('Resampling method' ), self .METHODS , 0 ))
81
- self .addParameter (ParameterSelection (self .FORMAT ,
82
- self .tr ('Overview format' ), self .FORMATS , 0 ))
83
- self .addOutput (OutputRaster (self .OUTPUT , self .tr ('Pyramidized' ), True ))
56
+ self .methods = ((self .tr ('Nearest neighbour' ), 'nearest' ),
57
+ (self .tr ('Average' ), 'average' ),
58
+ (self .tr ('Gaussian' ), 'gauss' ),
59
+ (self .tr ('Cubic convolution.' ), 'cubic' ),
60
+ (self .tr ('B-Spline convolution' ), 'cubicspline' ),
61
+ (self .tr ('Lanczos windowed sinc' ), 'lanczos' ),
62
+ (self .tr ('Average MP' ), 'average_mp' ),
63
+ (self .tr ('Average in mag/phase space' ), 'average_magphase' ),
64
+ (self .tr ('Mode' ), 'mode' ))
65
+
66
+ self .formats = (self .tr ('Internal (if possible)' ),
67
+ self .tr ('External (GTiff .ovr)' ),
68
+ self .tr ('External (ERDAS Imagine .aux)' ))
69
+
70
+ self .addParameter (QgsProcessingParameterRasterLayer (self .INPUT ,
71
+ self .tr ('Input layer' )))
72
+ self .addParameter (QgsProcessingParameterString (self .LEVELS ,
73
+ self .tr ('Overview levels' ),
74
+ defaultValue = '2 4 8 16' ))
75
+ self .addParameter (QgsProcessingParameterBoolean (self .CLEAN ,
76
+ self .tr ('Remove all existing overviews' ),
77
+ defaultValue = False ))
78
+
79
+ params = []
80
+ params .append (QgsProcessingParameterEnum (self .RESAMPLING ,
81
+ self .tr ('Resampling method' ),
82
+ options = [i [0 ] for i in self .methods ],
83
+ allowMultiple = False ,
84
+ defaultValue = 0 ))
85
+ params .append (QgsProcessingParameterEnum (self .FORMAT ,
86
+ self .tr ('Overviews format' ),
87
+ options = self .formats ,
88
+ allowMultiple = False ,
89
+ defaultValue = 0 ))
90
+
91
+ self .addOutput (QgsProcessingOutputRasterLayer (self .OUTPUT , self .tr ('Pyramidized' )))
84
92
85
93
def name (self ):
86
94
return 'overviews'
@@ -91,26 +99,30 @@ def displayName(self):
91
99
def group (self ):
92
100
return self .tr ('Raster miscellaneous' )
93
101
102
+ def icon (self ):
103
+ return QIcon (os .path .join (pluginPath , 'images' , 'gdaltools' , 'raster-overview.png' ))
104
+
94
105
def getConsoleCommands (self , parameters , context , feedback ):
95
- inFile = self .getParameterValue (self .INPUT )
96
- clearOverviews = self .getParameterValue (self .CLEAN )
97
- ovrFormat = self .getParameterValue (self .FORMAT )
106
+ inLayer = self .parameterAsRasterLayer (parameters , self .INPUT , context )
107
+ fileName = inLayer .source ()
98
108
99
109
arguments = []
100
- arguments .append (inFile )
101
- if clearOverviews :
102
- arguments .append ('-clean' )
110
+ arguments .append (fileName )
111
+
103
112
arguments .append ('-r' )
104
- arguments .append (self .METHODS [self .getParameterValue ( self .RESAMPLING_METHOD ) ])
113
+ arguments .append (self .methods [self .parameterAsEnum ( parameters , self .RESAMPLING , context )][ 1 ])
105
114
115
+ ovrFormat = self .parameterAsEnum (parameters , self .FORMAT , context )
106
116
if ovrFormat == 1 :
107
- # external .ovr
108
117
arguments .append ('-ro' )
109
118
elif ovrFormat == 2 :
110
- # external .aux
111
119
arguments .extend ('--config USE_RRD YES' .split (' ' ))
112
120
113
- arguments .extend (self .getParameterValue (self .LEVELS ).split (' ' ))
114
- self .setOutputValue (self .OUTPUT , inFile )
121
+ if self .parameterAsBool (parameters , self .CLEAN , context ):
122
+ arguments .append ('-clean' )
123
+
124
+ arguments .extend (self .parameterAsString (parameters , self .LEVELS , context ).split (' ' ))
125
+
126
+ self .setOutputValue (self .OUTPUT , fileName )
115
127
116
128
return ['gdaladdo' , GdalUtils .escapeAndJoin (arguments )]
0 commit comments