Skip to content
Permalink
Browse files

[processing] aded dual support for saga 2.1 and 2.0.8

several minor bugs and improvements
  • Loading branch information
volaya committed Aug 25, 2013
1 parent 75ed1a7 commit 78264a0720110289c984697df12694231088b5ca
@@ -149,8 +149,7 @@ def execute(self, progress):
self.runPreExecutionScript(progress)
self.processAlgorithm(progress)
self.convertUnsupportedFormats(progress)
self.runPostExecutionScript(progress)
print self.crs.authid()
self.runPostExecutionScript(progress)
except GeoAlgorithmExecutionException, gaee:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, gaee.msg)
raise gaee
@@ -59,7 +59,7 @@ def initialize():
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.KEEP_DIALOG_OPEN, "Keep dialog open after running an algorithm", False))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.USE_SELECTED, "Use only selected features", True))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.TABLE_LIKE_PARAM_PANEL, "Show table-like parameter panels", False))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.USE_FILENAME_AS_LAYER_NAME, "Use filename as layer name", True))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.USE_FILENAME_AS_LAYER_NAME, "Use filename as layer name", False))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.SHOW_RECENT_ALGORITHMS, "Show recently executed algorithms", True))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.OUTPUT_FOLDER, "Output folder", ProcessingUtils.tempFolder()))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.SHOW_CRS_DEF, "Show layer CRS definition in selection boxes", True))
@@ -23,7 +23,7 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4 import QtCore, QtGui, QtWebKit
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import webbrowser
@@ -36,21 +36,24 @@ def __init__(self, wrongLayers, alg):
self.setupUi()

def setupUi(self):
self.resize(800,400)
self.resize(600,350)
self.setWindowTitle("Problem loading output layers")
layout = QVBoxLayout()
webView = QtWebKit.QWebView()
webView.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks)
webView.connect(webView, SIGNAL("linkClicked(const QUrl&)"), self.linkClicked)
browser = QtGui.QTextBrowser()
browser.setOpenLinks(False)
browser.anchorClicked.connect(self.linkClicked)
html = self.alg.getPostProcessingErrorMessage(self.wrongLayers)
webView.setHtml(html)
closeButton = QtGui.QPushButton()
closeButton.setText("Close")
QObject.connect(closeButton, QtCore.SIGNAL("clicked()"), self.closeButtonPressed)
layout.addWidget(webView)
layout.addWidget(closeButton)
browser.setHtml(html)
button = QPushButton()
button.setText("Close")
button.clicked.connect(self.closeButtonPressed)
buttonBox = QtGui.QDialogButtonBox()
buttonBox.setOrientation(QtCore.Qt.Horizontal)
buttonBox.addButton(button, QDialogButtonBox.ActionRole)
layout.addWidget(browser)
layout.addWidget(buttonBox)
self.setLayout(layout)
QtCore.QMetaObject.connectSlotsByName(self)


def linkClicked(self, url):
webbrowser.open(str(url))
@@ -38,15 +38,17 @@ def setupUi(self):
self.resize(500,300)
self.setWindowTitle("Missing dependency")
layout = QVBoxLayout()
webView = QtWebKit.QWebView()
webView.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks)
webView.connect(webView, SIGNAL("linkClicked(const QUrl&)"), self.linkClicked)
webView.setHtml(self.msg)
closeButton = QtGui.QPushButton()
closeButton.setText("Close")
QObject.connect(closeButton, QtCore.SIGNAL("clicked()"), self.closeButtonPressed)
layout.addWidget(webView)
layout.addWidget(closeButton)
browser = QtGui.QTextBrowser()
browser.anchorClicked.connect(self.linkClicked)
browser.setHtml(self.msg)
button = QPushButton()
button.setText("Close")
button.clicked.connect(self.closeButtonPressed)
buttonBox = QtGui.QDialogButtonBox()
buttonBox.setOrientation(QtCore.Qt.Horizontal)
buttonBox.addButton(button, QDialogButtonBox.ActionRole)
layout.addWidget(browser)
layout.addWidget(buttonBox)
self.setLayout(layout)
QtCore.QMetaObject.connectSlotsByName(self)

@@ -100,7 +100,7 @@ def setParamValues(self):
self.values = {}
self.outputs = {}

name = self.getSafeNameForHarcodedParameter(self.alg.getParameterFromName(self.alg.FORMULA))
name = self.getSafeNameForHarcodedParameter(self.alg.getParameterFromName(self.alg.FORMULA))
value = AlgorithmAndParameter(AlgorithmAndParameter.PARENT_MODEL_ALGORITHM, name)
self.params[self.alg.FORMULA] = value
formula = str(self.formulaText.text())
@@ -130,8 +130,8 @@ def setParamValues(self):
return True

def getSafeNameForHarcodedParameter(self, param):
if self.algIndex is None:
return "HARDCODEDPARAMVALUE_" + param.name + "_" + str(self.alg)
if self.algIndex is not None:
return "HARDCODEDPARAMVALUE_" + param.name + "_" + str(self.algIndex)
else:
return "HARDCODEDPARAMVALUE_" + param.name + "_" + str(len(self.model.algs))

@@ -178,7 +178,7 @@ def openModel(self, filename):
#we add the output to the algorithm, with a name indicating where it comes from
#that guarantees that the name is unique
output = copy.deepcopy(out)
output.description = line
output.description = name
output.name = self.getSafeNameForOutput(iAlg, output)
self.addOutput(output)
else:
@@ -415,7 +415,8 @@ def fillAlgorithmTreeUsingProviders(self):
class TreeAlgorithmItem(QTreeWidgetItem):

def __init__(self, alg):
useCategories = ProcessingConfig.getSetting(ModelerDialog.USE_CATEGORIES)
settings = QSettings()
useCategories = settings.value(ModelerDialog.USE_CATEGORIES, type = bool)
QTreeWidgetItem.__init__(self)
self.alg = alg
icon = alg.getIcon()
@@ -44,11 +44,11 @@ def getValueAsCommandLineParameter(self):
def getAsScriptCode(self):
return "##" + self.name + "=field " + str(self.parent)

def setValue(self, field):
if field is None:
def setValue(self, value):
if value is None:
return self.optional
elif len(field) > 0:
self.value = str(field)
elif len(value) > 0:
self.value = str(value)
else:
return self.optional
return True
@@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from processing.parameters.ParameterTableField import ParameterTableField

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@@ -237,7 +238,8 @@ def processAlgorithm(self, progress):
raise GeoAlgorithmExecutionException("Unsupported file format")

#2: set parameters and outputs
if ProcessingUtils.isWindows() or ProcessingUtils.isMac():
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
if ProcessingUtils.isWindows() or ProcessingUtils.isMac() or not saga208:
command = self.undecoratedGroup + " \"" + self.cmdname + "\""
else:
command = "lib" + self.undecoratedGroup + " \"" + self.cmdname + "\""
@@ -304,8 +306,9 @@ def processAlgorithm(self, progress):
if isinstance(out, OutputRaster):
filename = out.getCompatibleFileName(self)
filename2 = ProcessingUtils.tempFolder() + os.sep + os.path.basename(filename) + ".sgrd"
if ProcessingUtils.isWindows() or ProcessingUtils.isMac():
commands.append("io_gdal 1 -GRIDS \"" + filename2 + "\" -FORMAT 4 -TYPE 0 -FILE \"" + filename + "\"");
formatIndex = 1 if saga208 else 4
if ProcessingUtils.isWindows() or ProcessingUtils.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 + "\"");

@@ -363,7 +366,8 @@ def resampleRasterLayer(self,layer):
inputFilename = layer
destFilename = ProcessingUtils.getTempFilename("sgrd")
self.exportedLayers[layer]= destFilename
if ProcessingUtils.isWindows() or ProcessingUtils.isMac():
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
if ProcessingUtils.isWindows() or ProcessingUtils.isMac() or not saga208:
s = "grid_tools \"Resampling\" -INPUT \"" + inputFilename + "\" -TARGET 0 -SCALE_UP_METHOD 4 -SCALE_DOWN_METHOD 4 -USER_XMIN " +\
str(self.xmin) + " -USER_XMAX " + str(self.xmax) + " -USER_YMIN " + str(self.ymin) + " -USER_YMAX " + str(self.ymax) +\
" -USER_SIZE " + str(self.cellsize) + " -USER_GRID \"" + destFilename + "\""
@@ -377,7 +381,8 @@ def resampleRasterLayer(self,layer):
def exportRasterLayer(self, layer):
destFilename = ProcessingUtils.getTempFilenameInTempFolder(os.path.basename(layer)[0:5] + ".sgrd")
self.exportedLayers[layer]= destFilename
if ProcessingUtils.isWindows() or ProcessingUtils.isMac():
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
if ProcessingUtils.isWindows() or ProcessingUtils.isMac() or not saga208:
return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer+"\""
else:
return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""
@@ -45,10 +45,11 @@ def __init__(self):
def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
if ProcessingUtils.isWindows():
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_FOLDER, "SAGA folder", SagaUtils.sagaPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_FOLDER, "SAGA folder", SagaUtils.sagaPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_208, "Enable SAGA 2.0.8 compatibility", False))
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_AUTO_RESAMPLING, "Use min covering grid system for resampling", True))
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_LOG_COMMANDS, "Log execution commands", False))
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_LOG_CONSOLE, "Log console output", False))
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_LOG_COMMANDS, "Log execution commands", True))
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_LOG_CONSOLE, "Log console output", True))
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_RESAMPLING_REGION_XMIN, "Resampling region min x", 0))
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_RESAMPLING_REGION_YMIN, "Resampling region min y", 0))
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_RESAMPLING_REGION_XMAX, "Resampling region max x", 1000))
@@ -70,10 +71,11 @@ def unload(self):

def createAlgsList(self):
self.preloadedAlgs = []
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
folder = SagaUtils.sagaDescriptionPath()
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith("txt"):
if ProcessingUtils.isWindows() or ProcessingUtils.isMac():
if not saga208:
if descriptionFile.startswith("2.0.8"):
continue
else:
@@ -36,6 +36,7 @@

class SagaUtils:

SAGA_208 = "SAGA_208"
SAGA_LOG_COMMANDS = "SAGA_LOG_COMMANDS"
SAGA_LOG_CONSOLE = "SAGA_LOG_CONSOLE"
SAGA_AUTO_RESAMPLING = "SAGA_AUTO_RESAMPLING"
@@ -0,0 +1,11 @@
Shapes Buffer
shapes_tools
ParameterVector|SHAPES|Shapes|-1|False
ParameterSelection|BUF_TYPE|Buffer Distance|[0] fixed value;[1] attribute field
ParameterNumber|BUF_DIST|Buffer Distance (Fixed)|None|None|100.0
ParameterTableField|BUF_FIELD|Buffer Distance (Attribute)|SHAPES|-1|False
ParameterNumber|BUF_SCALE|Scaling Factor for Attribute Value|None|None|1.0
ParameterNumber|BUF_ZONES|Number of Buffer Zones|1.0|None|1.0
ParameterNumber|DCIRCLE|Circle Point Distance [Degree]|None|None|5.0
ParameterBoolean|DISSOLVE |Dissolve Buffers|True
OutputVector|BUFFER|Buffer
@@ -2,11 +2,10 @@ Catchment Area (Mass-Flux Method)
ta_hydrology
ParameterRaster|DEM|Elevation|False
ParameterSelection|METHOD|Flow Split Method|[0] flow width (original);[1] cell area
ParameterBoolean|B_SLOPE |Slope|True
ParameterBoolean|B_ASPECT |Aspect|True
ParameterBoolean|B_AREA |Flow Accumulation|True
ParameterBoolean|B_FLOW |Flow Lines|True
OutputRaster|AREA|Flow Accumulation
Harcoded|-B_SLOPE
Harcoded|B_ASPECT
Harcoded|B_AREA
Harcoded|B_FLOW
OutputRaster|G_SLOPE|Slope
OutputRaster|G_ASPECT|Aspect
OutputRaster|G_AREA|Flow Accumulation
@@ -1,6 +1,6 @@
Split Shapes Layer Randomly
shapes_tools
ParameterVector|SHAPES|Shapes|-1|False
ParameterNumber|PERCENT|Relation B / A|None|None|1
ParameterNumber|PERCENT|Split ratio (%)|0|100|50
OutputVector|A|Group A
OutputVector|B|Group B

This file was deleted.

0 comments on commit 78264a0

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