Skip to content

Commit aa60bfe

Browse files
committed
[processing] New system for handling SAGA versions
This commit sets a different way of handling SAGA versions and a new way of checking saga installations This is done to fix the messy situation that SAGA causes due to its API changing in each release.
1 parent 3bd9709 commit aa60bfe

File tree

500 files changed

+2741
-553
lines changed

Some content is hidden

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

500 files changed

+2741
-553
lines changed

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

-68
This file was deleted.

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

+15-69
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19-
from processing.gui.Help2Html import getHtmlFromRstFile
19+
2020

2121
__author__ = 'Victor Olaya'
2222
__date__ = 'August 2012'
@@ -30,23 +30,23 @@
3030
from qgis.core import *
3131
from PyQt4.QtCore import *
3232
from PyQt4.QtGui import *
33-
33+
from processing.gui.Help2Html import getHtmlFromRstFile
3434
from processing.core.GeoAlgorithm import GeoAlgorithm
3535
from processing.core.ProcessingConfig import ProcessingConfig
3636
from processing.core.ProcessingLog import ProcessingLog
3737
from processing.core.GeoAlgorithmExecutionException import \
3838
GeoAlgorithmExecutionException
3939
from processing.core.parameters import *
4040
from processing.core.outputs import *
41-
from SagaUtils import SagaUtils
41+
import SagaUtils
4242
from SagaGroupNameDecorator import SagaGroupNameDecorator
4343
from processing.tools import dataobjects
4444
from processing.tools.system import *
4545

4646
sessionExportedLayers = {}
4747

4848

49-
class SagaAlgorithm(GeoAlgorithm):
49+
class SagaAlgorithm212(GeoAlgorithm):
5050

5151
OUTPUT_EXTENT = 'OUTPUT_EXTENT'
5252

@@ -58,7 +58,7 @@ def __init__(self, descriptionfile):
5858
self.defineCharacteristicsFromFile()
5959

6060
def getCopy(self):
61-
newone = SagaAlgorithm(self.descriptionFile)
61+
newone = SagaAlgorithm212(self.descriptionFile)
6262
newone.provider = self.provider
6363
return newone
6464

@@ -100,12 +100,6 @@ def defineCharacteristicsFromFile(self):
100100

101101

102102
def processAlgorithm(self, progress):
103-
if isWindows():
104-
path = SagaUtils.sagaPath()
105-
if path == '':
106-
raise GeoAlgorithmExecutionException(
107-
'SAGA folder is not configured.\nPlease configure \
108-
it before running SAGA algorithms.')
109103
commands = list()
110104
self.exportedLayers = {}
111105

@@ -165,12 +159,7 @@ def processAlgorithm(self, progress):
165159
'Unsupported file format')
166160

167161
# 2: Set parameters and outputs
168-
saga208 = SagaUtils.isSaga208()
169-
if isWindows() or isMac() or not saga208:
170-
command = self.undecoratedGroup + ' "' + self.cmdname + '"'
171-
else:
172-
command = 'lib' + self.undecoratedGroup + ' "' + self.cmdname + '"'
173-
162+
command = self.undecoratedGroup + ' "' + self.cmdname + '"'
174163
if self.hardcodedStrings:
175164
for s in self.hardcodedStrings:
176165
command += ' ' + s
@@ -240,7 +229,7 @@ def processAlgorithm(self, progress):
240229
if isinstance(out, OutputRaster):
241230
filename = out.getCompatibleFileName(self)
242231
filename2 = filename + '.sgrd'
243-
formatIndex = (4 if not saga208 and isWindows() else 1)
232+
formatIndex = (4 if isWindows() else 1)
244233
sessionExportedLayers[filename] = filename2
245234
dontExport = True
246235

@@ -256,23 +245,14 @@ def processAlgorithm(self, progress):
256245
# continue
257246

258247
if self.cmdname == 'RGB Composite':
259-
if isWindows() or isMac() or not saga208:
260-
commands.append('io_grid_image 0 -IS_RGB -GRID:"' + filename2
261-
+ '" -FILE:"' + filename
262-
+ '"')
263-
else:
264-
commands.append('libio_grid_image 0 -IS_RGB -GRID:"' + filename2
248+
commands.append('io_grid_image 0 -IS_RGB -GRID:"' + filename2
265249
+ '" -FILE:"' + filename
266250
+ '"')
267251
else:
268-
if isWindows() or isMac() or not saga208:
269-
commands.append('io_gdal 1 -GRIDS "' + filename2
270-
+ '" -FORMAT ' + str(formatIndex)
271-
+ ' -TYPE 0 -FILE "' + filename + '"')
272-
else:
273-
commands.append('libio_gdal 1 -GRIDS "' + filename2
274-
+ '" -FORMAT 1 -TYPE 0 -FILE "' + filename
275-
+ '"')
252+
commands.append('io_gdal 1 -GRIDS "' + filename2
253+
+ '" -FORMAT ' + str(formatIndex)
254+
+ ' -TYPE 0 -FILE "' + filename + '"')
255+
276256

277257
# 4: Run SAGA
278258
commands = self.editCommands(commands)
@@ -339,28 +319,7 @@ def exportRasterLayer(self, source):
339319
destFilename = getTempFilenameInTempFolder(filename + '.sgrd')
340320
self.exportedLayers[source] = destFilename
341321
sessionExportedLayers[source] = destFilename
342-
saga208 = SagaUtils.isSaga208()
343-
if saga208:
344-
if isWindows() or isMac():
345-
return 'io_gdal 0 -GRIDS "' + destFilename + '" -FILES "' + source \
346-
+ '"'
347-
else:
348-
return 'libio_gdal 0 -GRIDS "' + destFilename + '" -FILES "' \
349-
+ source + '"'
350-
else:
351-
return 'io_gdal 0 -TRANSFORM -INTERPOL 0 -GRIDS "' + destFilename + '" -FILES "' + source \
352-
+ '"'
353-
354-
def checkBeforeOpeningParametersDialog(self):
355-
msg = SagaUtils.checkSagaIsInstalled()
356-
if msg is not None:
357-
print msg
358-
html = '<p>This algorithm requires SAGA to be run.Unfortunately, \
359-
it seems that SAGA is not installed in your system, or it \
360-
is not correctly configured to be used from QGIS</p>'
361-
html += '<p><a href= "http://docs.qgis.org/2.0/en/docs/user_manual/processing/3rdParty.html">\
362-
Click here</a> to know more about how to install and configure SAGA to be used with QGIS</p>'
363-
return html
322+
return 'io_gdal 0 -TRANSFORM -INTERPOL 0 -GRIDS "' + destFilename + '" -FILES "' + source + '"'
364323

365324
def checkParameterValuesBeforeExecuting(self):
366325
"""
@@ -372,7 +331,8 @@ def checkParameterValuesBeforeExecuting(self):
372331
files = []
373332
if isinstance(param, ParameterRaster):
374333
files = [param.value]
375-
elif isinstance(param, ParameterMultipleInput) and param.datatype == ParameterMultipleInput.TYPE_RASTER:
334+
elif (isinstance(param, ParameterMultipleInput) and
335+
param.datatype == ParameterMultipleInput.TYPE_RASTER):
376336
if param.value is not None:
377337
files = param.value.split(";")
378338
for f in files:
@@ -405,17 +365,3 @@ def help(self):
405365
html = ('<img src="%s"/>' % imgpath) + html
406366
return True, html
407367

408-
def getPostProcessingErrorMessage(self, wrongLayers):
409-
html = GeoAlgorithm.getPostProcessingErrorMessage(self, wrongLayers)
410-
msg = SagaUtils.checkSagaIsInstalled(True)
411-
html += '<p>This algorithm requires SAGA to be run. A test to check \
412-
if SAGA is correctly installed and configured in your system \
413-
has been performed, with the following result:</p><ul><i>'
414-
if msg is None:
415-
html += 'SAGA seems to be correctly installed and \
416-
configured</li></ul>'
417-
else:
418-
html += msg + '</i></li></ul>'
419-
html += '<p><a href= "http://docs.qgis.org/2.0/en/docs/user_manual/processing/3rdParty.html">Click here</a> to know more about how to install and configure SAGA to be used with QGIS</p>'
420-
421-
return html

0 commit comments

Comments
 (0)