65
65
class SagaAlgorithm (GeoAlgorithm ):
66
66
67
67
OUTPUT_EXTENT = 'OUTPUT_EXTENT'
68
+ RESAMPLING = "_RESAMPLING"
68
69
69
70
def __init__ (self , descriptionfile ):
70
71
GeoAlgorithm .__init__ (self )
71
72
self .hardcodedStrings = []
72
73
self .allowUnmatchingGridExtents = False
74
+ self .noResamplingChoice = False
73
75
self .descriptionFile = descriptionfile
74
76
self .defineCharacteristicsFromFile ()
75
77
self ._icon = None
@@ -115,6 +117,8 @@ def defineCharacteristicsFromFile(self):
115
117
self .addParameter (getParameterFromString (line ))
116
118
elif line .startswith ('AllowUnmatching' ):
117
119
self .allowUnmatchingGridExtents = True
120
+ elif line .startswith ('NoResamplingChoice' ):
121
+ self .noResamplingChoice = True
118
122
elif line .startswith ('Extent' ):
119
123
# An extent parameter that wraps 4 SAGA numerical parameters
120
124
self .extentParamNames = line [6 :].strip ().split (' ' )
@@ -123,6 +127,21 @@ def defineCharacteristicsFromFile(self):
123
127
else :
124
128
self .addOutput (getOutputFromString (line ))
125
129
line = lines .readline ().strip ('\n ' ).strip ()
130
+ hasRaster = False
131
+ hasHardcodedResampling = False
132
+ for param in self .parameters :
133
+ if isinstance (param , ParameterRaster ) or
134
+ (isinstance (param , ParameterMultipleInput )
135
+ and param .type == ParameterMultipleInput .TYPE_RASTER ):
136
+ hasRaster = True
137
+ break ;
138
+
139
+ if (not self .noResamplingChoice and
140
+ not self .forceNearestNeighbour and hasRaster ):
141
+ param = ParameterSelection (self .RESAMPLING , "Resampling method" , ["Nearest Neighbour" , "Bilinear Interpolation" , "Bicubic Spline Interpolation" , "B-Spline Interpolation" ], 3 )
142
+ param .isAdvanced = True
143
+ self .addParameter (param )
144
+
126
145
127
146
def processAlgorithm (self , progress ):
128
147
commands = list ()
@@ -196,7 +215,7 @@ def processAlgorithm(self, progress):
196
215
command += ' ' + ' ' .join (self .hardcodedStrings )
197
216
198
217
for param in self .parameters :
199
- if param .value is None :
218
+ if param .value is None or param . name == self . RESAMPLING :
200
219
continue
201
220
if isinstance (param , (ParameterRaster , ParameterVector , ParameterTable )):
202
221
value = param .value
@@ -327,7 +346,9 @@ def exportRasterLayer(self, source):
327
346
destFilename = getTempFilenameInTempFolder (filename + '.sgrd' )
328
347
self .exportedLayers [source ] = destFilename
329
348
sessionExportedLayers [source ] = destFilename
330
- return 'io_gdal 0 -TRANSFORM 1 -RESAMPLING 3 -GRIDS "' + destFilename + '" -FILES "' + source + '"'
349
+ resampling = self .getParameterValue (self .RESAMPLING )
350
+ resampling = str (resampling ) if resampling is not None else "0"
351
+ return 'io_gdal 0 -TRANSFORM 1 -RESAMPLING ' + resampling + ' -GRIDS "' + destFilename + '" -FILES "' + source + '"'
331
352
332
353
def checkParameterValuesBeforeExecuting (self ):
333
354
"""
0 commit comments