Skip to content

Commit 9a7b06a

Browse files
committedMay 30, 2017
[processing] support only SAGA LTR
1 parent dcd99ad commit 9a7b06a

File tree

1,683 files changed

+87
-13268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,683 files changed

+87
-13268
lines changed
 
Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
FILE(GLOB PY_FILES *.py)
2-
FILE(GLOB DESCR212_FILES description/2.1.2/*.txt)
3-
FILE(GLOB DESCR213_FILES description/2.1.3/*.txt)
4-
FILE(GLOB DESCR214_FILES description/2.1.4/*.txt)
5-
FILE(GLOB DESCR220_FILES description/2.2.0/*.txt)
6-
FILE(GLOB DESCR222_FILES description/2.2.2/*.txt)
7-
FILE(GLOB DESCR223_FILES description/2.2.3/*.txt)
8-
FILE(GLOB DESCR230_FILES description/2.3.0/*.txt)
9-
FILE(GLOB HELP_FILES help/*.rst)
2+
FILE(GLOB DESCR_FILES description/*.txt)
103

114
ADD_SUBDIRECTORY(ext)
125

136
PLUGIN_INSTALL(processing algs/saga ${PY_FILES})
14-
PLUGIN_INSTALL(processing algs/saga/description/2.1.2 ${DESCR212_FILES})
15-
PLUGIN_INSTALL(processing algs/saga/description/2.1.3 ${DESCR213_FILES})
16-
PLUGIN_INSTALL(processing algs/saga/description/2.1.4 ${DESCR214_FILES})
17-
PLUGIN_INSTALL(processing algs/saga/description/2.2.0 ${DESCR220_FILES})
18-
PLUGIN_INSTALL(processing algs/saga/description/2.2.2 ${DESCR222_FILES})
19-
PLUGIN_INSTALL(processing algs/saga/description/2.2.3 ${DESCR223_FILES})
20-
PLUGIN_INSTALL(processing algs/saga/description/2.3.0 ${DESCR230_FILES})
21-
PLUGIN_INSTALL(processing algs/saga/help ${HELP_FILES})
7+
PLUGIN_INSTALL(processing algs/saga/description/ ${DESCR_FILES})

‎python/plugins/processing/algs/saga/SagaAlgorithm212.py renamed to ‎python/plugins/processing/algs/saga/SagaAlgorithm.py

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
* *
1717
***************************************************************************
1818
"""
19+
from future import standard_library
20+
standard_library.install_aliases()
21+
from builtins import str
22+
from builtins import range
1923

2024

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

6064

61-
class SagaAlgorithm212(GeoAlgorithm):
65+
class SagaAlgorithm(GeoAlgorithm):
6266

6367
OUTPUT_EXTENT = 'OUTPUT_EXTENT'
6468

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

7277
def getCopy(self):
73-
newone = SagaAlgorithm212(self.descriptionFile)
78+
newone = SagaAlgorithm(self.descriptionFile)
7479
newone.provider = self.provider
7580
return newone
7681

7782
def getIcon(self):
78-
return QIcon(os.path.join(pluginPath, 'images', 'saga.png'))
83+
if self._icon is None:
84+
self._icon = QIcon(os.path.join(pluginPath, 'images', 'saga.png'))
85+
return self._icon
7986

8087
def defineCharacteristicsFromFile(self):
81-
lines = open(self.descriptionFile)
82-
line = lines.readline().strip('\n').strip()
83-
self.name = line
84-
if '|' in self.name:
85-
tokens = self.name.split('|')
86-
self.name = tokens[0]
87-
#cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console
88-
self.cmdname = tokens[1]
88+
with open(self.descriptionFile) as lines:
89+
line = lines.readline().strip('\n').strip()
90+
self.name = line
91+
if '|' in self.name:
92+
tokens = self.name.split('|')
93+
self.name = tokens[0]
94+
#cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console
95+
self.cmdname = tokens[1]
8996

90-
else:
91-
self.cmdname = self.name
92-
self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", unicode(self.name))
93-
#_commandLineName is the name used in processing to call the algorithm
94-
#Most of the time will be equal to the cmdname, but in same cases, several processing algorithms
95-
#call the same SAGA one
96-
self._commandLineName = self.createCommandLineName(self.name)
97-
self.name = decoratedAlgorithmName(self.name)
98-
self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", unicode(self.name))
99-
line = lines.readline().strip('\n').strip()
100-
self.undecoratedGroup = line
101-
self.group = decoratedGroupName(self.undecoratedGroup)
102-
self.i18n_group = QCoreApplication.translate("SAGAAlgorithm", self.group)
103-
line = lines.readline().strip('\n').strip()
104-
while line != '':
105-
if line.startswith('Hardcoded'):
106-
self.hardcodedStrings.append(line[len('Hardcoded|'):])
107-
elif line.startswith('Parameter'):
108-
self.addParameter(getParameterFromString(line))
109-
elif line.startswith('AllowUnmatching'):
110-
self.allowUnmatchingGridExtents = True
111-
elif line.startswith('Extent'):
112-
# An extent parameter that wraps 4 SAGA numerical parameters
113-
self.extentParamNames = line[6:].strip().split(' ')
114-
self.addParameter(ParameterExtent(self.OUTPUT_EXTENT,
115-
'Output extent', ''))
11697
else:
117-
self.addOutput(getOutputFromString(line))
98+
self.cmdname = self.name
99+
self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", str(self.name))
100+
#_commandLineName is the name used in processing to call the algorithm
101+
#Most of the time will be equal to the cmdname, but in same cases, several processing algorithms
102+
#call the same SAGA one
103+
self._commandLineName = self.createCommandLineName(self.name)
104+
self.name = decoratedAlgorithmName(self.name)
105+
self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", str(self.name))
106+
line = lines.readline().strip('\n').strip()
107+
self.undecoratedGroup = line
108+
self.group = decoratedGroupName(self.undecoratedGroup)
109+
self.i18n_group = QCoreApplication.translate("SAGAAlgorithm", self.group)
118110
line = lines.readline().strip('\n').strip()
119-
lines.close()
111+
while line != '':
112+
if line.startswith('Hardcoded'):
113+
self.hardcodedStrings.append(line[len('Hardcoded|'):])
114+
elif line.startswith('Parameter'):
115+
self.addParameter(getParameterFromString(line))
116+
elif line.startswith('AllowUnmatching'):
117+
self.allowUnmatchingGridExtents = True
118+
elif line.startswith('Extent'):
119+
# An extent parameter that wraps 4 SAGA numerical parameters
120+
self.extentParamNames = line[6:].strip().split(' ')
121+
self.addParameter(ParameterExtent(self.OUTPUT_EXTENT,
122+
'Output extent'))
123+
else:
124+
self.addOutput(getOutputFromString(line))
125+
line = lines.readline().strip('\n').strip()
120126

121127
def processAlgorithm(self, progress):
122128
commands = list()
@@ -162,7 +168,7 @@ def processAlgorithm(self, progress):
162168
layers = param.value.split(';')
163169
if layers is None or len(layers) == 0:
164170
continue
165-
if param.datatype == ParameterMultipleInput.TYPE_RASTER:
171+
if param.datatype == dataobjects.TYPE_RASTER:
166172
for i, layerfile in enumerate(layers):
167173
if layerfile.endswith('sdat'):
168174
layerfile = param.value[:-4] + "sgrd"
@@ -172,10 +178,10 @@ def processAlgorithm(self, progress):
172178
if exportCommand is not None:
173179
commands.append(exportCommand)
174180
param.value = ";".join(layers)
175-
elif param.datatype in [ParameterMultipleInput.TYPE_VECTOR_ANY,
176-
ParameterMultipleInput.TYPE_VECTOR_LINE,
177-
ParameterMultipleInput.TYPE_VECTOR_POLYGON,
178-
ParameterMultipleInput.TYPE_VECTOR_POINT]:
181+
elif param.datatype in [dataobjects.TYPE_VECTOR_ANY,
182+
dataobjects.TYPE_VECTOR_LINE,
183+
dataobjects.TYPE_VECTOR_POLYGON,
184+
dataobjects.TYPE_VECTOR_POINT]:
179185
for layerfile in layers:
180186
layer = dataobjects.getObjectFromUri(layerfile, False)
181187
if layer:
@@ -194,28 +200,27 @@ def processAlgorithm(self, progress):
194200
continue
195201
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable)):
196202
value = param.value
197-
if value in self.exportedLayers.keys():
203+
if value in list(self.exportedLayers.keys()):
198204
command += ' -' + param.name + ' "' \
199205
+ self.exportedLayers[value] + '"'
200206
else:
201207
command += ' -' + param.name + ' "' + value + '"'
202208
elif isinstance(param, ParameterMultipleInput):
203209
s = param.value
204-
for layer in self.exportedLayers.keys():
210+
for layer in list(self.exportedLayers.keys()):
205211
s = s.replace(layer, self.exportedLayers[layer])
206212
command += ' -' + param.name + ' "' + s + '"'
207213
elif isinstance(param, ParameterBoolean):
208214
if param.value:
209215
command += ' -' + param.name
210216
elif isinstance(param, ParameterFixedTable):
211217
tempTableFile = getTempFilename('txt')
212-
f = open(tempTableFile, 'w')
213-
f.write('\t'.join([col for col in param.cols]) + '\n')
214-
values = param.value.split(',')
215-
for i in range(0, len(values), 3):
216-
s = values[i] + '\t' + values[i + 1] + '\t' + values[i + 2] + '\n'
217-
f.write(s)
218-
f.close()
218+
with open(tempTableFile, 'w') as f:
219+
f.write('\t'.join([col for col in param.cols]) + '\n')
220+
values = param.value.split(',')
221+
for i in range(0, len(values), 3):
222+
s = values[i] + '\t' + values[i + 1] + '\t' + values[i + 2] + '\n'
223+
f.write(s)
219224
command += ' -' + param.name + ' "' + tempTableFile + '"'
220225
elif isinstance(param, ParameterExtent):
221226
# 'We have to substract/add half cell size, since SAGA is
@@ -225,11 +230,11 @@ def processAlgorithm(self, progress):
225230
values = param.value.split(',')
226231
for i in range(4):
227232
command += ' -' + self.extentParamNames[i] + ' ' \
228-
+ unicode(float(values[i]) + offset[i])
233+
+ str(float(values[i]) + offset[i])
229234
elif isinstance(param, (ParameterNumber, ParameterSelection)):
230-
command += ' -' + param.name + ' ' + unicode(param.value)
235+
command += ' -' + param.name + ' ' + str(param.value)
231236
else:
232-
command += ' -' + param.name + ' "' + unicode(param.value) + '"'
237+
command += ' -' + param.name + ' "' + str(param.value) + '"'
233238

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

290295
def getOutputCellsize(self):
291-
"""Tries to guess the cellsize of the output, searching for
296+
"""Tries to guess the cell size of the output, searching for
292297
a parameter with an appropriate name for it.
293298
"""
294299

@@ -310,7 +315,7 @@ def exportRasterLayer(self, source):
310315
del sessionExportedLayers[source]
311316
layer = dataobjects.getObjectFromUri(source, False)
312317
if layer:
313-
filename = unicode(layer.name())
318+
filename = str(layer.name())
314319
else:
315320
filename = os.path.basename(source)
316321
validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:'
@@ -333,7 +338,7 @@ def checkParameterValuesBeforeExecuting(self):
333338
if isinstance(param, ParameterRaster):
334339
files = [param.value]
335340
elif (isinstance(param, ParameterMultipleInput) and
336-
param.datatype == ParameterMultipleInput.TYPE_RASTER):
341+
param.datatype == dataobjects.TYPE_RASTER):
337342
if param.value is not None:
338343
files = param.value.split(";")
339344
for f in files:
@@ -342,7 +347,7 @@ def checkParameterValuesBeforeExecuting(self):
342347
continue
343348
if layer.bandCount() > 1:
344349
return self.tr('Input layer %s has more than one band.\n'
345-
'Multiband layers are not supported by SAGA' % unicode(layer.name()))
350+
'Multiband layers are not supported by SAGA' % str(layer.name()))
346351
if not self.allowUnmatchingGridExtents:
347352
if extent is None:
348353
extent = (layer.extent(), layer.height(), layer.width())

0 commit comments

Comments
 (0)
Please sign in to comment.