Skip to content

Commit

Permalink
[processing] aded dual support for saga 2.1 and 2.0.8
Browse files Browse the repository at this point in the history
several minor bugs and improvements
  • Loading branch information
volaya committed Aug 25, 2013
1 parent 75ed1a7 commit 78264a0
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 52 deletions.
3 changes: 1 addition & 2 deletions python/plugins/processing/core/GeoAlgorithm.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/core/ProcessingConfig.py
Expand Up @@ -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))
Expand Down
27 changes: 15 additions & 12 deletions python/plugins/processing/gui/CouldNotLoadResultsDialog.py
Expand Up @@ -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
Expand All @@ -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))
Expand Down
20 changes: 11 additions & 9 deletions python/plugins/processing/gui/MissingDependencyDialog.py
Expand Up @@ -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)

Expand Down
Expand Up @@ -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())
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/modeler/ModelerAlgorithm.py
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/parameters/ParameterTableField.py
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions python/plugins/processing/saga/SagaAlgorithm.py
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from processing.parameters.ParameterTableField import ParameterTableField

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -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 + "\""
Expand Down Expand Up @@ -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 + "\"");

Expand Down Expand Up @@ -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 + "\""
Expand All @@ -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 + "\""
Expand Down
10 changes: 6 additions & 4 deletions python/plugins/processing/saga/SagaAlgorithmProvider.py
Expand Up @@ -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))
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/saga/SagaUtils.py
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions python/plugins/processing/saga/description/2.1_ShapesBuffer.txt
@@ -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
Expand Up @@ -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
Expand Down
@@ -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.