Skip to content

Commit

Permalink
fixed grass algorithms
Browse files Browse the repository at this point in the history
fixed bug when using multiple layers in saga (#5652)

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@198 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed May 31, 2012
1 parent d2c7008 commit ce52bb5
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/sextante/grass/DefineGrassRegionAction.py
Expand Up @@ -32,8 +32,10 @@ def fillCoords(self):
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMIN, r.yMinimum())
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMAX, r.xMaximum())
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMAX, r.yMaximum())
SextanteConfig.setSettingValue(GrassUtils.GRASS_AUTO_REGION, False)
s = str(r.xMinimum()) + "," + str(r.xMaximum()) + "," + str(r.yMinimum()) + "," + str(r.yMaximum())
self.tool.reset()
canvas = QGisLayers.iface.mapCanvas()
canvas.setMapTool(self.prevMapTool)
QtGui.QMessageBox.information(None, "GRASS Region", "GRASS region set to:\n" + s)
QtGui.QMessageBox.information(None, "GRASS Region", "GRASS region set to:\n" + s + \
"\nTo set the cellsize or set back the autoregion option,\ngo to the SEXTANTE configuration.")
7 changes: 7 additions & 0 deletions src/sextante/grass/description/v.to.rast.attribute.txt
@@ -0,0 +1,7 @@
v.to.rast
v.to.rast.attribute
Vector (v.*)
ParameterVector|input|input|-1|False
ParameterSelection|use|use|attr
ParameterTableField|column|column|input
OutputRaster|output|output
8 changes: 0 additions & 8 deletions src/sextante/grass/description/v.to.rast.txt

This file was deleted.

7 changes: 7 additions & 0 deletions src/sextante/grass/description/v.to.rast.value.txt
@@ -0,0 +1,7 @@
v.to.rast
v.to.rast.value
Vector (v.*)
ParameterVector|input|input|-1|False
ParameterSelection|use|use|val
ParameterNumber|value|value|None|None|1
OutputRaster|output|output
17 changes: 10 additions & 7 deletions src/sextante/gui/ConfigDialog.py
Expand Up @@ -41,11 +41,13 @@ def setupUi(self):
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
if SextanteUtils.isWindows():
self.externalAppsButton = QtGui.QPushButton()
self.externalAppsButton.setText("Configure external apps")
self.horizontalLayout.addWidget(self.externalAppsButton)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("clicked()"), self.configureExternalApps)
#=======================================================================
# if SextanteUtils.isWindows():
# self.externalAppsButton = QtGui.QPushButton()
# self.externalAppsButton.setText("Configure external apps")
# self.horizontalLayout.addWidget(self.externalAppsButton)
# QtCore.QObject.connect(self.externalAppsButton, QtCore.SIGNAL("clicked()"), self.configureExternalApps)
#=======================================================================
self.horizontalLayout.addSpacing(100)
self.horizontalLayout.addWidget(self.buttonBox)
self.verticalLayout.addLayout(self.horizontalLayout)
Expand All @@ -55,8 +57,9 @@ def setupUi(self):
QtCore.QMetaObject.connectSlotsByName(self)

def configureExternalApps(self):
ExternalAppsConfigurer.configure()
#TODO find a way to automate
configurer = ExternalAppsConfigurer()
configurer.configure()


def fillTree(self):
self.items = {}
Expand Down
38 changes: 33 additions & 5 deletions src/sextante/gui/ExternalAppsConfigurer.py
@@ -1,10 +1,38 @@
import os
from sextante.gui.InteractiveHTMLViewerDialog import InteractiveHTMLViewerDialog
class ExternalAppsConfigurer():

@staticmethod
def configure():
def configure(self):
#TODO find a way of automating this, not having to add each provider here manually
settings = {}
folders = self.findFolder("c:\\","saga")
settings["SAGA binaries folder"] = folders
folders['SAGA'] = settings

pass
html = ""
for key in settings.keys():
html += self.createHTMLSection(settings[key], key)

def folderFinder(self, s):
pass
dialog = InteractiveHTMLViewerDialog(html, self)
dialog.exec_()

def findFolder(self, head, name):
name = name.upper()
found = []
for root, dirs, files in os.walk(head):
for d in dirs:
if d.upper().endswith(name):
found.append(os.path.join(root, d))
return found

def createHTMLSection(self, settings, name):
html = "<h2>" + name.upper() + "</h2>\n"
html += "<ul>\n"
for key, setting in settings.items():
html += "<li>" + key + " : " + setting[0] + "</li>\n"
if len(setting) > 1:
html += "<ul>\n"
for i in range(1, len(setting)):
html += "<li><a href=\"" + key + "|" + str(i) + ">" + setting[i] + "</a></li>\n"
html += "<ul>\n"
html += "<ul>\n"
46 changes: 46 additions & 0 deletions src/sextante/gui/InteractiveHTMLViewerDialog.py
@@ -0,0 +1,46 @@
from PyQt4 import QtCore, QtGui, QtWebKit
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class InteractiveHTMLViewerDialog(QtGui.QDialog):

def __init__(self, html, linkHandler):
QtGui.QDialog.__init__(self)
self.html = html
self.linkHandler = linkHandler
self.setModal(True)
self.setupUi()

def setupUi(self):
self.resize(600, 500)
self.webView = QtWebKit.QWebView()
self.webView.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks)
self.setWindowTitle("Help")
self.closeButton = QtGui.QPushButton()
self.closeButton.setText("Close")
self.closeButton.setMaximumWidth(150)
self.horizontalLayout= QtGui.QHBoxLayout()
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.addStretch(1000)
self.horizontalLayout.addWidget(self.closeButton)
self.verticalLayout= QtGui.QVBoxLayout()
self.verticalLayout.setSpacing(2)
self.verticalLayout.setMargin(0)
self.verticalLayout.addWidget(self.webView)
self.verticalLayout.addLayout(self.horizontalLayout)
self.setLayout(self.verticalLayout)
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.closeWindow)
QObject.connect(self.webView, SIGNAL("linkClicked(const QUrl&)"), self.linkClicked)
try:
url = QtCore.QUrl(self.filename)
self.webView.load(url)
except:
pass

def linkClicked(self, url):
pass


def closeWindow(self):
self.close()
6 changes: 2 additions & 4 deletions src/sextante/saga/SagaAlgorithm.py
Expand Up @@ -25,6 +25,7 @@
from sextante.core.LayerExporter import LayerExporter
import subprocess
from sextante.parameters.ParameterExtent import ParameterExtent
from PyQt4 import QtGui

class SagaAlgorithm(GeoAlgorithm):

Expand Down Expand Up @@ -192,7 +193,7 @@ def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(layerfile, False)
if layer:
filename = LayerExporter.exportVectorLayer(layer)
self.exportedLayers[param.value]=filename
self.exportedLayers[layerfile]=filename
elif (not value.endswith("shp")):
raise GeoAlgorithmExecutionException("Unsupported file format")

Expand Down Expand Up @@ -228,9 +229,6 @@ def processAlgorithm(self, progress):
else:
command+=(" -" + param.name + " \"" + str(param.value) + "\"");




for out in self.outputs:
if isinstance(out, OutputRaster):
filename = out.value
Expand Down

0 comments on commit ce52bb5

Please sign in to comment.