Skip to content
Permalink
Browse files

[processing] support only SAGA LTR

  • Loading branch information
alexbruy committed May 30, 2017
1 parent dcd99ad commit 9a7b06aaf45e78aa05d0d115c0a11ec61bffd1db
Showing 1,683 changed files with 87 additions and 13,268 deletions.
@@ -1,21 +1,7 @@
FILE(GLOB PY_FILES *.py)
FILE(GLOB DESCR212_FILES description/2.1.2/*.txt)
FILE(GLOB DESCR213_FILES description/2.1.3/*.txt)
FILE(GLOB DESCR214_FILES description/2.1.4/*.txt)
FILE(GLOB DESCR220_FILES description/2.2.0/*.txt)
FILE(GLOB DESCR222_FILES description/2.2.2/*.txt)
FILE(GLOB DESCR223_FILES description/2.2.3/*.txt)
FILE(GLOB DESCR230_FILES description/2.3.0/*.txt)
FILE(GLOB HELP_FILES help/*.rst)
FILE(GLOB DESCR_FILES description/*.txt)

ADD_SUBDIRECTORY(ext)

PLUGIN_INSTALL(processing algs/saga ${PY_FILES})
PLUGIN_INSTALL(processing algs/saga/description/2.1.2 ${DESCR212_FILES})
PLUGIN_INSTALL(processing algs/saga/description/2.1.3 ${DESCR213_FILES})
PLUGIN_INSTALL(processing algs/saga/description/2.1.4 ${DESCR214_FILES})
PLUGIN_INSTALL(processing algs/saga/description/2.2.0 ${DESCR220_FILES})
PLUGIN_INSTALL(processing algs/saga/description/2.2.2 ${DESCR222_FILES})
PLUGIN_INSTALL(processing algs/saga/description/2.2.3 ${DESCR223_FILES})
PLUGIN_INSTALL(processing algs/saga/description/2.3.0 ${DESCR230_FILES})
PLUGIN_INSTALL(processing algs/saga/help ${HELP_FILES})
PLUGIN_INSTALL(processing algs/saga/description/ ${DESCR_FILES})
@@ -16,6 +16,10 @@
* *
***************************************************************************
"""
from future import standard_library
standard_library.install_aliases()
from builtins import str
from builtins import range


__author__ = 'Victor Olaya'
@@ -58,7 +62,7 @@
sessionExportedLayers = {}


class SagaAlgorithm212(GeoAlgorithm):
class SagaAlgorithm(GeoAlgorithm):

OUTPUT_EXTENT = 'OUTPUT_EXTENT'

@@ -68,55 +72,57 @@ def __init__(self, descriptionfile):
self.allowUnmatchingGridExtents = False
self.descriptionFile = descriptionfile
self.defineCharacteristicsFromFile()
self._icon = None

def getCopy(self):
newone = SagaAlgorithm212(self.descriptionFile)
newone = SagaAlgorithm(self.descriptionFile)
newone.provider = self.provider
return newone

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'saga.png'))
if self._icon is None:
self._icon = QIcon(os.path.join(pluginPath, 'images', 'saga.png'))
return self._icon

def defineCharacteristicsFromFile(self):
lines = open(self.descriptionFile)
line = lines.readline().strip('\n').strip()
self.name = line
if '|' in self.name:
tokens = self.name.split('|')
self.name = tokens[0]
#cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console
self.cmdname = tokens[1]
with open(self.descriptionFile) as lines:
line = lines.readline().strip('\n').strip()
self.name = line
if '|' in self.name:
tokens = self.name.split('|')
self.name = tokens[0]
#cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console
self.cmdname = tokens[1]

else:
self.cmdname = self.name
self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", unicode(self.name))
#_commandLineName is the name used in processing to call the algorithm
#Most of the time will be equal to the cmdname, but in same cases, several processing algorithms
#call the same SAGA one
self._commandLineName = self.createCommandLineName(self.name)
self.name = decoratedAlgorithmName(self.name)
self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", unicode(self.name))
line = lines.readline().strip('\n').strip()
self.undecoratedGroup = line
self.group = decoratedGroupName(self.undecoratedGroup)
self.i18n_group = QCoreApplication.translate("SAGAAlgorithm", self.group)
line = lines.readline().strip('\n').strip()
while line != '':
if line.startswith('Hardcoded'):
self.hardcodedStrings.append(line[len('Hardcoded|'):])
elif line.startswith('Parameter'):
self.addParameter(getParameterFromString(line))
elif line.startswith('AllowUnmatching'):
self.allowUnmatchingGridExtents = True
elif line.startswith('Extent'):
# An extent parameter that wraps 4 SAGA numerical parameters
self.extentParamNames = line[6:].strip().split(' ')
self.addParameter(ParameterExtent(self.OUTPUT_EXTENT,
'Output extent', ''))
else:
self.addOutput(getOutputFromString(line))
self.cmdname = self.name
self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", str(self.name))
#_commandLineName is the name used in processing to call the algorithm
#Most of the time will be equal to the cmdname, but in same cases, several processing algorithms
#call the same SAGA one
self._commandLineName = self.createCommandLineName(self.name)
self.name = decoratedAlgorithmName(self.name)
self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", str(self.name))
line = lines.readline().strip('\n').strip()
self.undecoratedGroup = line
self.group = decoratedGroupName(self.undecoratedGroup)
self.i18n_group = QCoreApplication.translate("SAGAAlgorithm", self.group)
line = lines.readline().strip('\n').strip()
lines.close()
while line != '':
if line.startswith('Hardcoded'):
self.hardcodedStrings.append(line[len('Hardcoded|'):])
elif line.startswith('Parameter'):
self.addParameter(getParameterFromString(line))
elif line.startswith('AllowUnmatching'):
self.allowUnmatchingGridExtents = True
elif line.startswith('Extent'):
# An extent parameter that wraps 4 SAGA numerical parameters
self.extentParamNames = line[6:].strip().split(' ')
self.addParameter(ParameterExtent(self.OUTPUT_EXTENT,
'Output extent'))
else:
self.addOutput(getOutputFromString(line))
line = lines.readline().strip('\n').strip()

def processAlgorithm(self, progress):
commands = list()
@@ -162,7 +168,7 @@ def processAlgorithm(self, progress):
layers = param.value.split(';')
if layers is None or len(layers) == 0:
continue
if param.datatype == ParameterMultipleInput.TYPE_RASTER:
if param.datatype == dataobjects.TYPE_RASTER:
for i, layerfile in enumerate(layers):
if layerfile.endswith('sdat'):
layerfile = param.value[:-4] + "sgrd"
@@ -172,10 +178,10 @@ def processAlgorithm(self, progress):
if exportCommand is not None:
commands.append(exportCommand)
param.value = ";".join(layers)
elif param.datatype in [ParameterMultipleInput.TYPE_VECTOR_ANY,
ParameterMultipleInput.TYPE_VECTOR_LINE,
ParameterMultipleInput.TYPE_VECTOR_POLYGON,
ParameterMultipleInput.TYPE_VECTOR_POINT]:
elif param.datatype in [dataobjects.TYPE_VECTOR_ANY,
dataobjects.TYPE_VECTOR_LINE,
dataobjects.TYPE_VECTOR_POLYGON,
dataobjects.TYPE_VECTOR_POINT]:
for layerfile in layers:
layer = dataobjects.getObjectFromUri(layerfile, False)
if layer:
@@ -194,28 +200,27 @@ def processAlgorithm(self, progress):
continue
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable)):
value = param.value
if value in self.exportedLayers.keys():
if value in list(self.exportedLayers.keys()):
command += ' -' + param.name + ' "' \
+ self.exportedLayers[value] + '"'
else:
command += ' -' + param.name + ' "' + value + '"'
elif isinstance(param, ParameterMultipleInput):
s = param.value
for layer in self.exportedLayers.keys():
for layer in list(self.exportedLayers.keys()):
s = s.replace(layer, self.exportedLayers[layer])
command += ' -' + param.name + ' "' + s + '"'
elif isinstance(param, ParameterBoolean):
if param.value:
command += ' -' + param.name
elif isinstance(param, ParameterFixedTable):
tempTableFile = getTempFilename('txt')
f = open(tempTableFile, 'w')
f.write('\t'.join([col for col in param.cols]) + '\n')
values = param.value.split(',')
for i in range(0, len(values), 3):
s = values[i] + '\t' + values[i + 1] + '\t' + values[i + 2] + '\n'
f.write(s)
f.close()
with open(tempTableFile, 'w') as f:
f.write('\t'.join([col for col in param.cols]) + '\n')
values = param.value.split(',')
for i in range(0, len(values), 3):
s = values[i] + '\t' + values[i + 1] + '\t' + values[i + 2] + '\n'
f.write(s)
command += ' -' + param.name + ' "' + tempTableFile + '"'
elif isinstance(param, ParameterExtent):
# 'We have to substract/add half cell size, since SAGA is
@@ -225,11 +230,11 @@ def processAlgorithm(self, progress):
values = param.value.split(',')
for i in range(4):
command += ' -' + self.extentParamNames[i] + ' ' \
+ unicode(float(values[i]) + offset[i])
+ str(float(values[i]) + offset[i])
elif isinstance(param, (ParameterNumber, ParameterSelection)):
command += ' -' + param.name + ' ' + unicode(param.value)
command += ' -' + param.name + ' ' + str(param.value)
else:
command += ' -' + param.name + ' "' + unicode(param.value) + '"'
command += ' -' + param.name + ' "' + str(param.value) + '"'

for out in self.outputs:
command += ' -' + out.name + ' "' + out.getCompatibleFileName(self) + '"'
@@ -288,7 +293,7 @@ def editCommands(self, commands):
return commands

def getOutputCellsize(self):
"""Tries to guess the cellsize of the output, searching for
"""Tries to guess the cell size of the output, searching for
a parameter with an appropriate name for it.
"""

@@ -310,7 +315,7 @@ def exportRasterLayer(self, source):
del sessionExportedLayers[source]
layer = dataobjects.getObjectFromUri(source, False)
if layer:
filename = unicode(layer.name())
filename = str(layer.name())
else:
filename = os.path.basename(source)
validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:'
@@ -333,7 +338,7 @@ def checkParameterValuesBeforeExecuting(self):
if isinstance(param, ParameterRaster):
files = [param.value]
elif (isinstance(param, ParameterMultipleInput) and
param.datatype == ParameterMultipleInput.TYPE_RASTER):
param.datatype == dataobjects.TYPE_RASTER):
if param.value is not None:
files = param.value.split(";")
for f in files:
@@ -342,7 +347,7 @@ def checkParameterValuesBeforeExecuting(self):
continue
if layer.bandCount() > 1:
return self.tr('Input layer %s has more than one band.\n'
'Multiband layers are not supported by SAGA' % unicode(layer.name()))
'Multiband layers are not supported by SAGA' % str(layer.name()))
if not self.allowUnmatchingGridExtents:
if extent is None:
extent = (layer.extent(), layer.height(), layer.width())

0 comments on commit 9a7b06a

Please sign in to comment.
You can’t perform that action at this time.