Skip to content

Commit 78264a0

Browse files
committed
[processing] aded dual support for saga 2.1 and 2.0.8
several minor bugs and improvements
1 parent 75ed1a7 commit 78264a0

16 files changed

+71
-52
lines changed

python/plugins/processing/core/GeoAlgorithm.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ def execute(self, progress):
149149
self.runPreExecutionScript(progress)
150150
self.processAlgorithm(progress)
151151
self.convertUnsupportedFormats(progress)
152-
self.runPostExecutionScript(progress)
153-
print self.crs.authid()
152+
self.runPostExecutionScript(progress)
154153
except GeoAlgorithmExecutionException, gaee:
155154
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, gaee.msg)
156155
raise gaee

python/plugins/processing/core/ProcessingConfig.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def initialize():
5959
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.KEEP_DIALOG_OPEN, "Keep dialog open after running an algorithm", False))
6060
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.USE_SELECTED, "Use only selected features", True))
6161
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.TABLE_LIKE_PARAM_PANEL, "Show table-like parameter panels", False))
62-
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.USE_FILENAME_AS_LAYER_NAME, "Use filename as layer name", True))
62+
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.USE_FILENAME_AS_LAYER_NAME, "Use filename as layer name", False))
6363
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.SHOW_RECENT_ALGORITHMS, "Show recently executed algorithms", True))
6464
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.OUTPUT_FOLDER, "Output folder", ProcessingUtils.tempFolder()))
6565
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.SHOW_CRS_DEF, "Show layer CRS definition in selection boxes", True))

python/plugins/processing/gui/CouldNotLoadResultsDialog.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# This will get replaced with a git SHA1 when you do a git archive
2424
__revision__ = '$Format:%H$'
2525

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

3838
def setupUi(self):
39-
self.resize(800,400)
39+
self.resize(600,350)
4040
self.setWindowTitle("Problem loading output layers")
4141
layout = QVBoxLayout()
42-
webView = QtWebKit.QWebView()
43-
webView.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks)
44-
webView.connect(webView, SIGNAL("linkClicked(const QUrl&)"), self.linkClicked)
42+
browser = QtGui.QTextBrowser()
43+
browser.setOpenLinks(False)
44+
browser.anchorClicked.connect(self.linkClicked)
4545
html = self.alg.getPostProcessingErrorMessage(self.wrongLayers)
46-
webView.setHtml(html)
47-
closeButton = QtGui.QPushButton()
48-
closeButton.setText("Close")
49-
QObject.connect(closeButton, QtCore.SIGNAL("clicked()"), self.closeButtonPressed)
50-
layout.addWidget(webView)
51-
layout.addWidget(closeButton)
46+
browser.setHtml(html)
47+
button = QPushButton()
48+
button.setText("Close")
49+
button.clicked.connect(self.closeButtonPressed)
50+
buttonBox = QtGui.QDialogButtonBox()
51+
buttonBox.setOrientation(QtCore.Qt.Horizontal)
52+
buttonBox.addButton(button, QDialogButtonBox.ActionRole)
53+
layout.addWidget(browser)
54+
layout.addWidget(buttonBox)
5255
self.setLayout(layout)
53-
QtCore.QMetaObject.connectSlotsByName(self)
56+
5457

5558
def linkClicked(self, url):
5659
webbrowser.open(str(url))

python/plugins/processing/gui/MissingDependencyDialog.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ def setupUi(self):
3838
self.resize(500,300)
3939
self.setWindowTitle("Missing dependency")
4040
layout = QVBoxLayout()
41-
webView = QtWebKit.QWebView()
42-
webView.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks)
43-
webView.connect(webView, SIGNAL("linkClicked(const QUrl&)"), self.linkClicked)
44-
webView.setHtml(self.msg)
45-
closeButton = QtGui.QPushButton()
46-
closeButton.setText("Close")
47-
QObject.connect(closeButton, QtCore.SIGNAL("clicked()"), self.closeButtonPressed)
48-
layout.addWidget(webView)
49-
layout.addWidget(closeButton)
41+
browser = QtGui.QTextBrowser()
42+
browser.anchorClicked.connect(self.linkClicked)
43+
browser.setHtml(self.msg)
44+
button = QPushButton()
45+
button.setText("Close")
46+
button.clicked.connect(self.closeButtonPressed)
47+
buttonBox = QtGui.QDialogButtonBox()
48+
buttonBox.setOrientation(QtCore.Qt.Horizontal)
49+
buttonBox.addButton(button, QDialogButtonBox.ActionRole)
50+
layout.addWidget(browser)
51+
layout.addWidget(buttonBox)
5052
self.setLayout(layout)
5153
QtCore.QMetaObject.connectSlotsByName(self)
5254

python/plugins/processing/modeler/CalculatorModelerParametersDialog.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def setParamValues(self):
100100
self.values = {}
101101
self.outputs = {}
102102

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

132132
def getSafeNameForHarcodedParameter(self, param):
133-
if self.algIndex is None:
134-
return "HARDCODEDPARAMVALUE_" + param.name + "_" + str(self.alg)
133+
if self.algIndex is not None:
134+
return "HARDCODEDPARAMVALUE_" + param.name + "_" + str(self.algIndex)
135135
else:
136136
return "HARDCODEDPARAMVALUE_" + param.name + "_" + str(len(self.model.algs))
137137

python/plugins/processing/modeler/ModelerAlgorithm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def openModel(self, filename):
178178
#we add the output to the algorithm, with a name indicating where it comes from
179179
#that guarantees that the name is unique
180180
output = copy.deepcopy(out)
181-
output.description = line
181+
output.description = name
182182
output.name = self.getSafeNameForOutput(iAlg, output)
183183
self.addOutput(output)
184184
else:

python/plugins/processing/modeler/ModelerDialog.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ def fillAlgorithmTreeUsingProviders(self):
415415
class TreeAlgorithmItem(QTreeWidgetItem):
416416

417417
def __init__(self, alg):
418-
useCategories = ProcessingConfig.getSetting(ModelerDialog.USE_CATEGORIES)
418+
settings = QSettings()
419+
useCategories = settings.value(ModelerDialog.USE_CATEGORIES, type = bool)
419420
QTreeWidgetItem.__init__(self)
420421
self.alg = alg
421422
icon = alg.getIcon()

python/plugins/processing/parameters/ParameterTableField.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def getValueAsCommandLineParameter(self):
4444
def getAsScriptCode(self):
4545
return "##" + self.name + "=field " + str(self.parent)
4646

47-
def setValue(self, field):
48-
if field is None:
47+
def setValue(self, value):
48+
if value is None:
4949
return self.optional
50-
elif len(field) > 0:
51-
self.value = str(field)
50+
elif len(value) > 0:
51+
self.value = str(value)
5252
else:
5353
return self.optional
5454
return True

python/plugins/processing/saga/SagaAlgorithm.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19+
from processing.parameters.ParameterTableField import ParameterTableField
1920

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

239240
#2: set parameters and outputs
240-
if ProcessingUtils.isWindows() or ProcessingUtils.isMac():
241+
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
242+
if ProcessingUtils.isWindows() or ProcessingUtils.isMac() or not saga208:
241243
command = self.undecoratedGroup + " \"" + self.cmdname + "\""
242244
else:
243245
command = "lib" + self.undecoratedGroup + " \"" + self.cmdname + "\""
@@ -304,8 +306,9 @@ def processAlgorithm(self, progress):
304306
if isinstance(out, OutputRaster):
305307
filename = out.getCompatibleFileName(self)
306308
filename2 = ProcessingUtils.tempFolder() + os.sep + os.path.basename(filename) + ".sgrd"
307-
if ProcessingUtils.isWindows() or ProcessingUtils.isMac():
308-
commands.append("io_gdal 1 -GRIDS \"" + filename2 + "\" -FORMAT 4 -TYPE 0 -FILE \"" + filename + "\"");
309+
formatIndex = 1 if saga208 else 4
310+
if ProcessingUtils.isWindows() or ProcessingUtils.isMac() or not saga208:
311+
commands.append("io_gdal 1 -GRIDS \"" + filename2 + "\" -FORMAT " + str(formatIndex) +" -TYPE 0 -FILE \"" + filename + "\"");
309312
else:
310313
commands.append("libio_gdal 1 -GRIDS \"" + filename2 + "\" -FORMAT 1 -TYPE 0 -FILE \"" + filename + "\"");
311314

@@ -363,7 +366,8 @@ def resampleRasterLayer(self,layer):
363366
inputFilename = layer
364367
destFilename = ProcessingUtils.getTempFilename("sgrd")
365368
self.exportedLayers[layer]= destFilename
366-
if ProcessingUtils.isWindows() or ProcessingUtils.isMac():
369+
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
370+
if ProcessingUtils.isWindows() or ProcessingUtils.isMac() or not saga208:
367371
s = "grid_tools \"Resampling\" -INPUT \"" + inputFilename + "\" -TARGET 0 -SCALE_UP_METHOD 4 -SCALE_DOWN_METHOD 4 -USER_XMIN " +\
368372
str(self.xmin) + " -USER_XMAX " + str(self.xmax) + " -USER_YMIN " + str(self.ymin) + " -USER_YMAX " + str(self.ymax) +\
369373
" -USER_SIZE " + str(self.cellsize) + " -USER_GRID \"" + destFilename + "\""
@@ -377,7 +381,8 @@ def resampleRasterLayer(self,layer):
377381
def exportRasterLayer(self, layer):
378382
destFilename = ProcessingUtils.getTempFilenameInTempFolder(os.path.basename(layer)[0:5] + ".sgrd")
379383
self.exportedLayers[layer]= destFilename
380-
if ProcessingUtils.isWindows() or ProcessingUtils.isMac():
384+
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
385+
if ProcessingUtils.isWindows() or ProcessingUtils.isMac() or not saga208:
381386
return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer+"\""
382387
else:
383388
return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""

python/plugins/processing/saga/SagaAlgorithmProvider.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ def __init__(self):
4545
def initializeSettings(self):
4646
AlgorithmProvider.initializeSettings(self)
4747
if ProcessingUtils.isWindows():
48-
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_FOLDER, "SAGA folder", SagaUtils.sagaPath()))
48+
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_FOLDER, "SAGA folder", SagaUtils.sagaPath()))
49+
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_208, "Enable SAGA 2.0.8 compatibility", False))
4950
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_AUTO_RESAMPLING, "Use min covering grid system for resampling", True))
50-
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_LOG_COMMANDS, "Log execution commands", False))
51-
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_LOG_CONSOLE, "Log console output", False))
51+
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_LOG_COMMANDS, "Log execution commands", True))
52+
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_LOG_CONSOLE, "Log console output", True))
5253
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_RESAMPLING_REGION_XMIN, "Resampling region min x", 0))
5354
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_RESAMPLING_REGION_YMIN, "Resampling region min y", 0))
5455
ProcessingConfig.addSetting(Setting(self.getDescription(), SagaUtils.SAGA_RESAMPLING_REGION_XMAX, "Resampling region max x", 1000))
@@ -70,10 +71,11 @@ def unload(self):
7071

7172
def createAlgsList(self):
7273
self.preloadedAlgs = []
74+
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
7375
folder = SagaUtils.sagaDescriptionPath()
7476
for descriptionFile in os.listdir(folder):
7577
if descriptionFile.endswith("txt"):
76-
if ProcessingUtils.isWindows() or ProcessingUtils.isMac():
78+
if not saga208:
7779
if descriptionFile.startswith("2.0.8"):
7880
continue
7981
else:

python/plugins/processing/saga/SagaUtils.py

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
class SagaUtils:
3838

39+
SAGA_208 = "SAGA_208"
3940
SAGA_LOG_COMMANDS = "SAGA_LOG_COMMANDS"
4041
SAGA_LOG_CONSOLE = "SAGA_LOG_CONSOLE"
4142
SAGA_AUTO_RESAMPLING = "SAGA_AUTO_RESAMPLING"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Shapes Buffer
2+
shapes_tools
3+
ParameterVector|SHAPES|Shapes|-1|False
4+
ParameterSelection|BUF_TYPE|Buffer Distance|[0] fixed value;[1] attribute field
5+
ParameterNumber|BUF_DIST|Buffer Distance (Fixed)|None|None|100.0
6+
ParameterTableField|BUF_FIELD|Buffer Distance (Attribute)|SHAPES|-1|False
7+
ParameterNumber|BUF_SCALE|Scaling Factor for Attribute Value|None|None|1.0
8+
ParameterNumber|BUF_ZONES|Number of Buffer Zones|1.0|None|1.0
9+
ParameterNumber|DCIRCLE|Circle Point Distance [Degree]|None|None|5.0
10+
ParameterBoolean|DISSOLVE |Dissolve Buffers|True
11+
OutputVector|BUFFER|Buffer

python/plugins/processing/saga/description/CatchmentArea(Mass-FluxMethod).txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ Catchment Area (Mass-Flux Method)
22
ta_hydrology
33
ParameterRaster|DEM|Elevation|False
44
ParameterSelection|METHOD|Flow Split Method|[0] flow width (original);[1] cell area
5-
ParameterBoolean|B_SLOPE |Slope|True
6-
ParameterBoolean|B_ASPECT |Aspect|True
7-
ParameterBoolean|B_AREA |Flow Accumulation|True
8-
ParameterBoolean|B_FLOW |Flow Lines|True
9-
OutputRaster|AREA|Flow Accumulation
5+
Harcoded|-B_SLOPE
6+
Harcoded|B_ASPECT
7+
Harcoded|B_AREA
8+
Harcoded|B_FLOW
109
OutputRaster|G_SLOPE|Slope
1110
OutputRaster|G_ASPECT|Aspect
1211
OutputRaster|G_AREA|Flow Accumulation
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Split Shapes Layer Randomly
22
shapes_tools
33
ParameterVector|SHAPES|Shapes|-1|False
4-
ParameterNumber|PERCENT|Relation B / A|None|None|1
4+
ParameterNumber|PERCENT|Split ratio (%)|0|100|50
55
OutputVector|A|Group A
66
OutputVector|B|Group B

python/plugins/processing/saga/description/ThiessenPolygons.txt

-4
This file was deleted.

0 commit comments

Comments
 (0)