Skip to content
Permalink
Browse files
Fixed bugs #5262, #5263, #5265 , #5266, #5267
Added numeric value selector
improved grass provider


git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@57 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed Apr 1, 2012
1 parent 0bd4ab3 commit c9b2d626820e3d209d9c98a824fd96d13aa1045e
Showing with 408 additions and 179 deletions.
  1. +1 −1 src/sextante/__init__.py
  2. +20 −15 src/sextante/core/AlgorithmProvider.py
  3. +32 −4 src/sextante/core/GeoAlgorithm.py
  4. +1 −1 src/sextante/core/QGisLayers.py
  5. +13 −16 src/sextante/core/Sextante.py
  6. +1 −1 src/sextante/core/SextanteConfig.py
  7. +0 −1 src/sextante/ftools/Delaunay.py
  8. +1 −1 src/sextante/ftools/LinesIntersection.py
  9. +4 −4 src/sextante/ftools/PointsInPolygon.py
  10. +4 −3 src/sextante/ftools/SumLines.py
  11. +1 −3 src/sextante/grass/GrassAlgorithm.py
  12. +9 −5 src/sextante/grass/GrassAlgorithmProvider.py
  13. +44 −56 src/sextante/grass/GrassUtils.py
  14. +5 −15 src/sextante/gui/AlgorithmExecutor.py
  15. +11 −13 src/sextante/gui/BatchProcessingDialog.py
  16. +83 −0 src/sextante/gui/NumberInputDialog.py
  17. +33 −0 src/sextante/gui/NumberInputPanel.py
  18. +5 −2 src/sextante/gui/OutputSelectionPanel.py
  19. +9 −2 src/sextante/gui/ParametersDialog.py
  20. +1 −1 src/sextante/mmqgis/DummyInterface.py
  21. +0 −1 src/sextante/modeler/CalculatorModelerParametersDialog.py
  22. +5 −3 src/sextante/r/RAlgorithm.py
  23. +5 −2 src/sextante/r/RAlgorithmProvider.py
  24. +1 −1 src/sextante/r/RUtils.py
  25. +15 −14 src/sextante/saga/SagaAlgorithm.py
  26. +5 −2 src/sextante/saga/SagaAlgorithmProvider.py
  27. +5 −6 src/sextante/saga/SagaUtils.py
  28. +0 −2 src/sextante/saga/UnwrappableSagaAlgorithmException.py
  29. +73 −1 src/sextanteexampleprovider/ExampleAlgorithm.py
  30. +21 −2 src/sextanteexampleprovider/ExampleAlgorithmProvider.py
  31. +0 −1 src/sextanteexampleprovider/SextanteExampleProviderPlugin.py
@@ -5,7 +5,7 @@ def name():
def description():
return "SEXTANTE Geoprocessing platform for QGIS"
def version():
return "Version 0.1"
return "Version 1.0"
def icon():
return "icon.png"
def qgisMinimumVersion():
@@ -12,6 +12,25 @@ def __init__(self):
self.actions = []
self.contextMenuActions = []

def loadAlgorithms(self):
self.algs = []
name = "ACTIVATE_" + self.getName().upper().replace(" ", "_")
if not SextanteConfig.getSetting(name):
return
else:
self._loadAlgorithms()

#methods to be overridden.
#==============================


def _loadAlgorithms(self):
'''Algorithm loading should take place here, filling self.algs, which is a list of
elements of class GeoAlgorithm. Use that class to create your own algorithms
Since algorithms should have a reference to the provider they come
from, this is also the place to set the 'provider' variable of each algorithm'''
pass

def initializeSettings(self):
'''this is the place where you should add config parameters to sextante using the SextanteConfig class.
this method is called when a provider is added to Sextante.
@@ -25,26 +44,12 @@ def unload(self):
Removal of config setting should be done here'''
name = "ACTIVATE_" + self.getName().upper().replace(" ", "_")
SextanteConfig.removeSetting(name)

def getName(self):
return "Generic algorithm provider"

def loadAlgorithms(self):
self.algs = []
name = "ACTIVATE_" + self.getName().upper().replace(" ", "_")
if not SextanteConfig.getSetting(name):
return
else:
self._loadAlgorithms()

#methods to be overridden.
#==============================

#Algorithm loading should take place here, filling self.algs, which is a list of
#elements of class GeoAlgorithm. Use that class to create your own algorithms
#Since algorithms should have a reference to the provider they come
#from, this is also the place to set the 'provider' variable of each algorithm
def _loadAlgorithms(self):
pass

def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/alg.png")
@@ -7,7 +7,9 @@
import os.path
from sextante.core.SextanteUtils import SextanteUtils
from sextante.parameters.ParameterMultipleInput import ParameterMultipleInput

from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
import traceback
from sextante.core.SextanteLog import SextanteLog

class GeoAlgorithm:

@@ -23,6 +25,10 @@ def __init__(self):
#change any of the following if your algorithm should not appear in the toolbox or modeler
self.showInToolbox = True
self.showInModeler = True
#true if the algorithm has been canceled while it was being executed
#default value is false, so it should be changed in processAlgorithm only if the algorithm
#gets canceled
self.canceled = False

self.defineCharacteristics()

@@ -32,6 +38,8 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/alg.png")

def helpFile(self):
'''Returns the path to the help file with the description of this algorithm.
It should be an HTML file'''
return None

def processAlgorithm(self):
@@ -43,7 +51,8 @@ def defineCharacteristics(self):
pass

def getCustomParametersDialog(self):
'''if the algorithm has a custom parameters dialog, it should be returned here, ready to be executed'''
'''if the algorithm has a custom parameters dialog, it should be returned
here, ready to be executed'''
return None

def getCustomModelerParametersDialog(self, modelAlg):
@@ -54,9 +63,29 @@ def getCustomModelerParametersDialog(self, modelAlg):
#=========================================================

def execute(self, progress):
'''The method to use to call a SEXTANTE algorithm.
Although the body of the algorithm is in processAlgorithm(),
it should be called using this method, since it performs
some additional operations.
The return value indicates whether the algorithm was canceled (false)
or successfully run (true).
Raises a GeoAlgorithmExecutionException in case anything goes wrong.'''
self.setOutputCRSFromInputLayers()
self.resolveTemporaryOutputs()
self.processAlgorithm(progress)
try:
self.processAlgorithm(progress)
return not self.canceled
except GeoAlgorithmExecutionException, gaee:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, gaee.msg)
raise gaee
except Exception, e:
#if something goes wrong and is not caught in the algorithm,
#we catch it here and wrap it
lines = []
lines.append(str(e))
lines.append(traceback.format_exc().replace("\n", "|"))
SextanteLog.addToLog(SextanteLog.LOG_ERROR, lines)
raise GeoAlgorithmExecutionException(str(e))

def resolveTemporaryOutputs(self):
'''sets temporary outputs (output.value = None) with a temporary file instead'''
@@ -152,7 +181,6 @@ def getOutputValue(self, name):
return out.value
return None


def getAsCommand(self):
'''Returns the command that would run this same algorithm from the console'''
s="Sextante.runalg(\"" + self.commandLineName() + "\","
@@ -1,7 +1,7 @@
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui
from PyQt4 import QtGui
from os import path
from sextante.core.SextanteConfig import SextanteConfig
import os.path
@@ -54,7 +54,7 @@ def removeProvider(provider):
Sextante.updateAlgsList()
except:
pass #This try catch block is here to avoid problems if the plugin with a provider is unloaded
#after SEXTANTEe itself has been unloaded. It is a quick fix before I found out how to
#after SEXTANTE itself has been unloaded. It is a quick fix before I found out how to
#properly avoid that

@staticmethod
@@ -82,6 +82,7 @@ def initialize():
Sextante.addProvider(ScriptAlgorithmProvider())
Sextante.addProvider(RAlgorithmProvider())
Sextante.addProvider(SagaAlgorithmProvider())
Sextante.addProvider(GrassAlgorithmProvider())
Sextante.modeler.initializeSettings();
#and initialize
SextanteLog.startLogging()
@@ -260,14 +261,11 @@ def runalg(name, *args):

SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, alg.getAsCommand())

try:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
AlgorithmExecutor.runalg(alg, SilentProgress())
QApplication.restoreOverrideCursor()
return alg.getOutputValuesAsDictionary()
except GeoAlgorithmExecutionException, e:
print "*****Error executing algorithm*****"
print e.msg
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
AlgorithmExecutor.runalg(alg, SilentProgress())
QApplication.restoreOverrideCursor()
return alg.getOutputValuesAsDictionary()


@staticmethod
def load(layer):
@@ -283,7 +281,7 @@ def loadFromAlg(layersdict):
@staticmethod
def getObject(uri):
'''Returns the QGIS object identified the given URI'''
QGisLayers.getObjectFromUri(uri)
return QGisLayers.getObjectFromUri(uri)

@staticmethod
def runandload(name, *args):
@@ -313,13 +311,12 @@ def runandload(name, *args):
return
i = i +1

try:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
AlgorithmExecutor.runalg(alg, SilentProgress())
QApplication.restoreOverrideCursor()
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
ret = AlgorithmExecutor.runalg(alg, SilentProgress())
QApplication.restoreOverrideCursor()
if ret:
SextantePostprocessing.handleAlgorithmResults(alg)
except GeoAlgorithmExecutionException, e:
QMessageBox.critical(None, "Error", e.msg)




@@ -80,7 +80,7 @@ def getSetting(name):


class Setting():

'''A simple config parameter that will appear on the SEXTANTE config dialog'''
def __init__(self, group, name, description, default):
self.group=group
self.name = name
@@ -6,7 +6,6 @@
from qgis.core import *
from sextante.parameters.ParameterVector import ParameterVector
from sextante.core.QGisLayers import QGisLayers
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.outputs.OutputVector import OutputVector
import voronoi
from sets import Set
@@ -46,7 +46,7 @@ def processAlgorithm(self, progress):
field2.setName(unicode(field2.name()) + "_2")
fieldList = {0:field1, 1:field2}
sRs = provider1.crs()
check = QFile(self.shapefileName)
check = QFile(output)
if check.exists():
if not QgsVectorFileWriter.deleteShapeFile(output):
raise GeoAlgorithmExecutionException("Could not delete existing output file")
@@ -32,7 +32,7 @@ def processAlgorithm(self, progress):
polyProvider = polyLayer.dataProvider()
pointProvider = pointLayer.dataProvider()
if polyProvider.crs() <> pointProvider.crs():
SextanteLog.addToLog(SextanteLog.LOG_WARNING,
SextanteLog.addToLog(SextanteLog.LOG_WARNING,
"CRS warning!Warning: Input layers have non-matching CRS.\nThis may cause unexpected results.")
allAttrs = polyProvider.attributeIndexes()
polyProvider.select(allAttrs)
@@ -45,10 +45,10 @@ def processAlgorithm(self, progress):
field = QgsField(unicode(inField), QVariant.Double, "real", 24, 15, "point count field")
fieldList[index] = field
sRs = polyProvider.crs()
check = QFile(self.shapefileName)
check = QFile(output)
if check.exists():
if not QgsVectorFileWriter.deleteShapeFile(self.shapefileName):
return
if not QgsVectorFileWriter.deleteShapeFile(output):
raise GeoAlgorithmExecutionException("could not delete file: " + output)
writer = QgsVectorFileWriter(output, systemEncoding, fieldList, polyProvider.geometryType(), sRs)
inFeat = QgsFeature()
inFeatB = QgsFeature()
@@ -10,6 +10,7 @@
from sextante.core.SextanteLog import SextanteLog
from sextante.ftools import ftools_utils
from sextante.parameters.ParameterString import ParameterString
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException

class SumLines(GeoAlgorithm):

@@ -53,10 +54,10 @@ def processAlgorithm(self, progress):
lineProvider.rewind()
start = 15.00
add = 85.00 / polyProvider.featureCount()
check = QFile(self.shapefileName)
check = QFile(output)
if check.exists():
if not QgsVectorFileWriter.deleteShapeFile(self.shapefileName):
return
if not QgsVectorFileWriter.deleteShapeFile(output):
raise GeoAlgorithmExecutionException("Could not delete existing output file")
writer = QgsVectorFileWriter(output, systemEncoding, fieldList, polyProvider.geometryType(), sRs)
#writer = QgsVectorFileWriter(outPath, "UTF-8", fieldList, polyProvider.geometryType(), sRs)
spatialIndex = ftools_utils.createIndex( lineProvider )
@@ -10,7 +10,6 @@
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterBoolean import ParameterBoolean
from sextante.outputs.OutputVector import OutputVector
from sextante.saga.SagaUtils import SagaUtils
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.core.SextanteLog import SextanteLog
from sextante.parameters.ParameterFactory import ParameterFactory
@@ -200,13 +199,12 @@ def processAlgorithm(self, progress):
commands.append(command)

#4 Run GRASS
GrassUtils.createGrassScript(commands)
loglines = []
loglines.append("GRASS execution commands")
for line in commands:
loglines.append(line)
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
GrassUtils.executeGrass(progress);
GrassUtils.executeGrass(commands, progress);


def exportVectorLayer(self, filename):
@@ -6,6 +6,7 @@
from sextante.core.SextanteLog import SextanteLog
from sextante.grass.GrassUtils import GrassUtils
from sextante.grass.GrassAlgorithm import GrassAlgorithm
from sextante.core.SextanteUtils import SextanteUtils

class GrassAlgorithmProvider(AlgorithmProvider):

@@ -15,29 +16,32 @@ def __init__(self):

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_FOLDER, "GRASS folder", GrassUtils.grassPath()))
if SextanteUtils.isWindows():
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_FOLDER, "GRASS folder", GrassUtils.grassPath()))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_WIN_SHELL, "Shell executable", GrassUtils.grassWinShell()))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_AUTO_REGION, "Use min covering region", True))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_LATLON, "Coordinates are lat/lon", False))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_REGION_XMIN, "GRASS Region min x", 0))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_REGION_YMIN, "GRASS Region min y", 0))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_REGION_XMAX, "GRASS Region max x", 1000))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_REGION_YMAX, "GRASS Region max y", 1000))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_REGION_CELLSIZE, "GRASS Region cellsize", 1))
SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_WIN_SHELL, "Shell executable (Windows only)", GrassUtils.grassWinShell()))

SextanteConfig.addSetting(Setting("GRASS", GrassUtils.GRASS_HELP_FOLDER, "GRASS help folder", GrassUtils.grassHelpPath()))
#SextanteConfig.addSetting(Setting("SAGA", SagaUtils.SAGA_USE_SELECTED, "Use only selected features in vector layers", False))

def unload(self):
AlgorithmProvider.unload(self)
SextanteConfig.removeSetting(GrassUtils.GRASS_FOLDER)
if SextanteUtils.isWindows():
SextanteConfig.removeSetting(GrassUtils.GRASS_FOLDER)
SextanteConfig.removeSetting(GrassUtils.GRASS_WIN_SHELL)
SextanteConfig.removeSetting(GrassUtils.GRASS_AUTO_REGION)
SextanteConfig.removeSetting(GrassUtils.GRASS_LATLON)
SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_XMIN)
SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_YMIN)
SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_XMAX)
SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_YMAX)
SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_CELLSIZE)
SextanteConfig.removeSetting(GrassUtils.GRASS_WIN_SHELL)
SextanteConfig.removeSetting(GrassUtils.GRASS_HELP_FOLDER)

def createAlgsList(self):
@@ -53,7 +57,7 @@ def createAlgsList(self):
else:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + descriptionFile)
except Exception,e:
pass
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + descriptionFile)

def _loadAlgorithms(self):
self.algs = self.preloadedAlgs

0 comments on commit c9b2d62

Please sign in to comment.