Skip to content

Commit bfa4988

Browse files
committed
[processing] add resampling method option for all albs that use raster layers
1 parent 2abb209 commit bfa4988

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

python/plugins/processing/algs/saga/SagaAlgorithm.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@
6565
class SagaAlgorithm(GeoAlgorithm):
6666

6767
OUTPUT_EXTENT = 'OUTPUT_EXTENT'
68+
RESAMPLING = "_RESAMPLING"
6869

6970
def __init__(self, descriptionfile):
7071
GeoAlgorithm.__init__(self)
7172
self.hardcodedStrings = []
7273
self.allowUnmatchingGridExtents = False
74+
self.noResamplingChoice = False
7375
self.descriptionFile = descriptionfile
7476
self.defineCharacteristicsFromFile()
7577
self._icon = None
@@ -115,6 +117,8 @@ def defineCharacteristicsFromFile(self):
115117
self.addParameter(getParameterFromString(line))
116118
elif line.startswith('AllowUnmatching'):
117119
self.allowUnmatchingGridExtents = True
120+
elif line.startswith('NoResamplingChoice'):
121+
self.noResamplingChoice = True
118122
elif line.startswith('Extent'):
119123
# An extent parameter that wraps 4 SAGA numerical parameters
120124
self.extentParamNames = line[6:].strip().split(' ')
@@ -123,6 +127,21 @@ def defineCharacteristicsFromFile(self):
123127
else:
124128
self.addOutput(getOutputFromString(line))
125129
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+
126145

127146
def processAlgorithm(self, progress):
128147
commands = list()
@@ -196,7 +215,7 @@ def processAlgorithm(self, progress):
196215
command += ' ' + ' '.join(self.hardcodedStrings)
197216

198217
for param in self.parameters:
199-
if param.value is None:
218+
if param.value is None or param.name == self.RESAMPLING:
200219
continue
201220
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable)):
202221
value = param.value
@@ -327,7 +346,9 @@ def exportRasterLayer(self, source):
327346
destFilename = getTempFilenameInTempFolder(filename + '.sgrd')
328347
self.exportedLayers[source] = destFilename
329348
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 + '"'
331352

332353
def checkParameterValuesBeforeExecuting(self):
333354
"""

python/plugins/processing/algs/saga/description/GridCalculator.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Raster calculator|Grid Calculator
22
grid_calculus
33
AllowUnmatching
4+
NoResamplingChoice
45
ParameterRaster|GRIDS|Main input layer|False
56
ParameterMultipleInput|XGRIDS|Additional layers|3|True
67
ParameterString|FORMULA|Formula|

python/plugins/processing/algs/saga/description/ReclassifyGridValues.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Reclassify Grid Values
22
grid_tools
3+
NoResamplingChoice
34
ParameterRaster|INPUT|Grid|False
45
ParameterSelection|METHOD|Method|[0] single;[1] range;[2] simple table
56
ParameterNumber|OLD|old value (for single value change)|None|None|0.0

0 commit comments

Comments
 (0)