Skip to content

Commit

Permalink
[processing] New system for handling SAGA versions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
volaya committed Jan 15, 2015
1 parent 3bd9709 commit aa60bfe
Show file tree
Hide file tree
Showing 502 changed files with 2,757 additions and 569 deletions.
68 changes: 0 additions & 68 deletions python/plugins/processing/algs/saga/RasterCalculator.py

This file was deleted.

Expand Up @@ -16,7 +16,7 @@
* *
***************************************************************************
"""
from processing.gui.Help2Html import getHtmlFromRstFile


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand All @@ -30,23 +30,23 @@
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from processing.gui.Help2Html import getHtmlFromRstFile
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
from processing.core.GeoAlgorithmExecutionException import \
GeoAlgorithmExecutionException
from processing.core.parameters import *
from processing.core.outputs import *
from SagaUtils import SagaUtils
import SagaUtils
from SagaGroupNameDecorator import SagaGroupNameDecorator
from processing.tools import dataobjects
from processing.tools.system import *

sessionExportedLayers = {}


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

OUTPUT_EXTENT = 'OUTPUT_EXTENT'

Expand All @@ -58,7 +58,7 @@ def __init__(self, descriptionfile):
self.defineCharacteristicsFromFile()

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

Expand Down Expand Up @@ -100,12 +100,6 @@ def defineCharacteristicsFromFile(self):


def processAlgorithm(self, progress):
if isWindows():
path = SagaUtils.sagaPath()
if path == '':
raise GeoAlgorithmExecutionException(
'SAGA folder is not configured.\nPlease configure \
it before running SAGA algorithms.')
commands = list()
self.exportedLayers = {}

Expand Down Expand Up @@ -165,12 +159,7 @@ def processAlgorithm(self, progress):
'Unsupported file format')

# 2: Set parameters and outputs
saga208 = SagaUtils.isSaga208()
if isWindows() or isMac() or not saga208:
command = self.undecoratedGroup + ' "' + self.cmdname + '"'
else:
command = 'lib' + self.undecoratedGroup + ' "' + self.cmdname + '"'

command = self.undecoratedGroup + ' "' + self.cmdname + '"'
if self.hardcodedStrings:
for s in self.hardcodedStrings:
command += ' ' + s
Expand Down Expand Up @@ -240,7 +229,7 @@ def processAlgorithm(self, progress):
if isinstance(out, OutputRaster):
filename = out.getCompatibleFileName(self)
filename2 = filename + '.sgrd'
formatIndex = (4 if not saga208 and isWindows() else 1)
formatIndex = (4 if isWindows() else 1)
sessionExportedLayers[filename] = filename2
dontExport = True

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

if self.cmdname == 'RGB Composite':
if isWindows() or isMac() or not saga208:
commands.append('io_grid_image 0 -IS_RGB -GRID:"' + filename2
+ '" -FILE:"' + filename
+ '"')
else:
commands.append('libio_grid_image 0 -IS_RGB -GRID:"' + filename2
commands.append('io_grid_image 0 -IS_RGB -GRID:"' + filename2
+ '" -FILE:"' + filename
+ '"')
else:
if isWindows() or isMac() or not saga208:
commands.append('io_gdal 1 -GRIDS "' + filename2
+ '" -FORMAT ' + str(formatIndex)
+ ' -TYPE 0 -FILE "' + filename + '"')
else:
commands.append('libio_gdal 1 -GRIDS "' + filename2
+ '" -FORMAT 1 -TYPE 0 -FILE "' + filename
+ '"')
commands.append('io_gdal 1 -GRIDS "' + filename2
+ '" -FORMAT ' + str(formatIndex)
+ ' -TYPE 0 -FILE "' + filename + '"')


# 4: Run SAGA
commands = self.editCommands(commands)
Expand Down Expand Up @@ -339,28 +319,7 @@ def exportRasterLayer(self, source):
destFilename = getTempFilenameInTempFolder(filename + '.sgrd')
self.exportedLayers[source] = destFilename
sessionExportedLayers[source] = destFilename
saga208 = SagaUtils.isSaga208()
if saga208:
if isWindows() or isMac():
return 'io_gdal 0 -GRIDS "' + destFilename + '" -FILES "' + source \
+ '"'
else:
return 'libio_gdal 0 -GRIDS "' + destFilename + '" -FILES "' \
+ source + '"'
else:
return 'io_gdal 0 -TRANSFORM -INTERPOL 0 -GRIDS "' + destFilename + '" -FILES "' + source \
+ '"'

def checkBeforeOpeningParametersDialog(self):
msg = SagaUtils.checkSagaIsInstalled()
if msg is not None:
print msg
html = '<p>This algorithm requires SAGA to be run.Unfortunately, \
it seems that SAGA is not installed in your system, or it \
is not correctly configured to be used from QGIS</p>'
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>'
return html
return 'io_gdal 0 -TRANSFORM -INTERPOL 0 -GRIDS "' + destFilename + '" -FILES "' + source + '"'

def checkParameterValuesBeforeExecuting(self):
"""
Expand All @@ -372,7 +331,8 @@ def checkParameterValuesBeforeExecuting(self):
files = []
if isinstance(param, ParameterRaster):
files = [param.value]
elif isinstance(param, ParameterMultipleInput) and param.datatype == ParameterMultipleInput.TYPE_RASTER:
elif (isinstance(param, ParameterMultipleInput) and
param.datatype == ParameterMultipleInput.TYPE_RASTER):
if param.value is not None:
files = param.value.split(";")
for f in files:
Expand Down Expand Up @@ -405,17 +365,3 @@ def help(self):
html = ('<img src="%s"/>' % imgpath) + html
return True, html

def getPostProcessingErrorMessage(self, wrongLayers):
html = GeoAlgorithm.getPostProcessingErrorMessage(self, wrongLayers)
msg = SagaUtils.checkSagaIsInstalled(True)
html += '<p>This algorithm requires SAGA to be run. A test to check \
if SAGA is correctly installed and configured in your system \
has been performed, with the following result:</p><ul><i>'
if msg is None:
html += 'SAGA seems to be correctly installed and \
configured</li></ul>'
else:
html += msg + '</i></li></ul>'
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>'

return html

0 comments on commit aa60bfe

Please sign in to comment.