Skip to content

Commit

Permalink
[processing] add resampling method option for all albs that use raste…
Browse files Browse the repository at this point in the history
…r layers
  • Loading branch information
volaya committed Aug 22, 2017
1 parent 2abb209 commit bfa4988
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
25 changes: 23 additions & 2 deletions python/plugins/processing/algs/saga/SagaAlgorithm.py
Expand Up @@ -65,11 +65,13 @@
class SagaAlgorithm(GeoAlgorithm):

OUTPUT_EXTENT = 'OUTPUT_EXTENT'
RESAMPLING = "_RESAMPLING"

def __init__(self, descriptionfile):
GeoAlgorithm.__init__(self)
self.hardcodedStrings = []
self.allowUnmatchingGridExtents = False
self.noResamplingChoice = False
self.descriptionFile = descriptionfile
self.defineCharacteristicsFromFile()
self._icon = None
Expand Down Expand Up @@ -115,6 +117,8 @@ def defineCharacteristicsFromFile(self):
self.addParameter(getParameterFromString(line))
elif line.startswith('AllowUnmatching'):
self.allowUnmatchingGridExtents = True
elif line.startswith('NoResamplingChoice'):
self.noResamplingChoice = True
elif line.startswith('Extent'):
# An extent parameter that wraps 4 SAGA numerical parameters
self.extentParamNames = line[6:].strip().split(' ')
Expand All @@ -123,6 +127,21 @@ def defineCharacteristicsFromFile(self):
else:
self.addOutput(getOutputFromString(line))
line = lines.readline().strip('\n').strip()
hasRaster = False
hasHardcodedResampling = False
for param in self.parameters:
if isinstance(param, ParameterRaster) or
(isinstance(param, ParameterMultipleInput)
and param.type == ParameterMultipleInput.TYPE_RASTER):
hasRaster = True
break;

if (not self.noResamplingChoice and
not self.forceNearestNeighbour and hasRaster):
param = ParameterSelection(self.RESAMPLING, "Resampling method", ["Nearest Neighbour", "Bilinear Interpolation", "Bicubic Spline Interpolation", "B-Spline Interpolation"], 3)
param.isAdvanced = True
self.addParameter(param)


def processAlgorithm(self, progress):
commands = list()
Expand Down Expand Up @@ -196,7 +215,7 @@ def processAlgorithm(self, progress):
command += ' ' + ' '.join(self.hardcodedStrings)

for param in self.parameters:
if param.value is None:
if param.value is None or param.name == self.RESAMPLING:
continue
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable)):
value = param.value
Expand Down Expand Up @@ -327,7 +346,9 @@ def exportRasterLayer(self, source):
destFilename = getTempFilenameInTempFolder(filename + '.sgrd')
self.exportedLayers[source] = destFilename
sessionExportedLayers[source] = destFilename
return 'io_gdal 0 -TRANSFORM 1 -RESAMPLING 3 -GRIDS "' + destFilename + '" -FILES "' + source + '"'
resampling = self.getParameterValue(self.RESAMPLING)
resampling = str(resampling) if resampling is not None else "0"
return 'io_gdal 0 -TRANSFORM 1 -RESAMPLING ' + resampling + ' -GRIDS "' + destFilename + '" -FILES "' + source + '"'

def checkParameterValuesBeforeExecuting(self):
"""
Expand Down
@@ -1,6 +1,7 @@
Raster calculator|Grid Calculator
grid_calculus
AllowUnmatching
NoResamplingChoice
ParameterRaster|GRIDS|Main input layer|False
ParameterMultipleInput|XGRIDS|Additional layers|3|True
ParameterString|FORMULA|Formula|
Expand Down
@@ -1,5 +1,6 @@
Reclassify Grid Values
grid_tools
NoResamplingChoice
ParameterRaster|INPUT|Grid|False
ParameterSelection|METHOD|Method|[0] single;[1] range;[2] simple table
ParameterNumber|OLD|old value (for single value change)|None|None|0.0
Expand Down

0 comments on commit bfa4988

Please sign in to comment.