Skip to content
Permalink
Browse files

Several changes. Now saga algorithms can be executed and also scripts…

…. Still have to test both, but it is more or less working fine

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@21 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf@gmail.com
volayaf@gmail.com committed Feb 3, 2012
1 parent 955454e commit 251343136c139cd505543b19bcf834dde1a3dcbb
Showing with 887 additions and 275 deletions.
  1. BIN images/config.png
  2. BIN images/documenter.png
  3. BIN images/grass.png
  4. BIN images/history.gif
  5. BIN images/model.png
  6. BIN images/r.png
  7. BIN images/saga.png
  8. BIN images/sextante.gif
  9. BIN images/sextante_toolbox.gif
  10. BIN images/sextante_toolbox2.gif
  11. +7 −3 src/{sextante/core/SextanteTest.py → Test.py}
  12. +0 −1 src/sextante/SextantePlugin.py
  13. +37 −6 src/sextante/core/GeoAlgorithm.py
  14. +5 −0 src/sextante/core/GeoAlgorithmExecutionException.py
  15. +66 −9 src/sextante/core/QGisLayers.py
  16. +55 −4 src/sextante/core/Sextante.py
  17. +61 −4 src/sextante/core/SextanteUtils.py
  18. +38 −0 src/sextante/gui/AlgorithmExecutor.py
  19. +5 −0 src/sextante/gui/ContextAction.py
  20. +22 −26 src/sextante/gui/ParametersDialog.py
  21. +61 −0 src/sextante/gui/ProgressDialog.py
  22. +19 −6 src/sextante/gui/SextanteToolbox.py
  23. +6 −0 src/sextante/gui/ToolboxAction.py
  24. +15 −34 src/sextante/outputs/Output.py
  25. +10 −27 src/sextante/parameters/Parameter.py
  26. +1 −1 src/sextante/parameters/ParameterBoolean.py
  27. +6 −10 src/sextante/parameters/ParameterDataObject.py
  28. +9 −26 src/sextante/parameters/ParameterFixedTable.py
  29. +51 −9 src/sextante/parameters/ParameterMultipleInput.py
  30. +14 −1 src/sextante/parameters/ParameterRange.py
  31. +15 −1 src/sextante/parameters/ParameterRaster.py
  32. +3 −1 src/sextante/parameters/ParameterString.py
  33. +24 −1 src/sextante/parameters/ParameterTable.py
  34. +14 −10 src/sextante/parameters/ParameterVector.py
  35. +69 −72 src/sextante/saga/SagaAlgorithm.py
  36. +3 −2 src/sextante/saga/SagaAlgorithmProvider.py
  37. +5 −2 src/sextante/saga/SagaBlackList.py
  38. +0 −4 src/sextante/saga/SagaExecutionException.py
  39. +37 −3 src/sextante/saga/SagaUtils.py
  40. +8 −2 src/sextante/script/CreateNewScriptAction.py
  41. +13 −0 src/sextante/script/DeleteScriptAction.py
  42. +14 −3 src/sextante/script/EditScriptAction.py
  43. +51 −0 src/sextante/script/EditScriptDialog.py
  44. +105 −1 src/sextante/script/ScriptAlgorithm.py
  45. +20 −6 src/sextante/script/ScriptAlgorithmProvider.py
  46. +13 −0 src/sextante/script/ScriptUtils.py
  47. +5 −0 src/sextante/script/WrongScriptException.py
BIN +611 Bytes images/config.png
Binary file not shown.
BIN +406 Bytes images/documenter.png
Binary file not shown.
BIN +750 Bytes images/grass.png
Binary file not shown.
BIN +146 Bytes images/history.gif
Binary file not shown.
BIN +843 Bytes images/model.png
Binary file not shown.
BIN +829 Bytes images/r.png
Binary file not shown.
BIN +245 Bytes images/saga.png
Binary file not shown.
BIN +1.03 KB images/sextante.gif
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,11 +1,15 @@
'''
Created on 13/01/2012
@author: volaya
'''
from sextante.core.Sextante import Sextante


def main():
Sextante.initialize()
print(Sextante.asStr())

Sextante.asStr()


if __name__ == '__main__':
main()
main()
@@ -44,7 +44,6 @@ def initGui(self):

def unload(self):
self.toolbox.setVisible(False)
menuBar = self.iface.mainWindow().menuBar()
self.menu.deleteLater()

def openToolbox(self):
@@ -1,5 +1,9 @@
from sextante.outputs.Output import Output
from sextante.parameters.Parameter import Parameter
from sextante.core.QGisLayers import QGisLayers
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.parameters.ParameterVector import ParameterVector


class GeoAlgorithm:

@@ -10,15 +14,25 @@ def __init__(self):
self.group = ""
self.defineCharacteristics()
self.providerName = ""
self.crs = None

def execute(self):
if self.checkParameters():
self.proccessAlgorithm()
def execute(self, progress):
self.setOutputCRSFromInputLayers()
self.processAlgorithm(progress)

def setOutputCRSFromInputLayers(self):
for param in self.parameters:
if isinstance(param, ParameterRaster):
layers = QGisLayers.getRasterLayers()
elif isinstance(param, ParameterVector):
layers = QGisLayers.getVectorLayers()
else:
continue
for layer in layers:
if layer.dataProvider().dataSourceUri() == param.value:
self.crs = layer.crs()
return

def checkParameters(self):
#TODO!!!!!!
return True

def defineCharacteristics(self):
pass
@@ -27,10 +41,12 @@ def processAlgorithm(self):
pass

def putOutput(self, output):
#TODO: check that name does not exist
if isinstance(output, Output):
self.outputs.append(output)

def putParameter(self, param):
#TODO: check that name does not exist
if isinstance(param, Parameter):
self.parameters.append(param)

@@ -57,7 +73,22 @@ def __str__(self):
s+=("\n")
return s


def commandLineName(self):
return self.providerName + self.name.lower().replace(" ", "")


def getOuputsChannelsAsMap(self):
retmap = {}
for out in self.outputs:
retmap[out.name] = out.channel
return retmap

def getAsCommand(self):
s="Sextante.runalg(\"" + self.commandLineName() + "\","
for param in self.parameters:
s+=param.getValueAsCommandLineParameter() + ","
for out in self.outputs:
s+=out.getChannelAsCommandLineParameter() + ","
s= s[:-1] + ")"
return s
@@ -0,0 +1,5 @@
class GeoAlgorithmExecutionException(Exception):

def __init__(self, msg):
Exception.__init__(self)
self.msg = msg
@@ -1,4 +1,8 @@
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui
from os import path

class QGisLayers:

@@ -23,26 +27,79 @@ def getVectorLayers():
layerNames.append(layer)
return layerNames

@staticmethod
def getTables():
layers = QGisLayers.iface.legendInterface().layers()
tables = list()
for layer in layers:
if layer.type() == layer.VectorLayer :
uri = str(layer.dataProvider().dataSourceUri())
if (uri.endswith("shp")):
tables.append(layer)
return tables

@staticmethod
def setInterface(iface):
QGisLayers.iface = iface


@staticmethod
def getLayersCount():
count = LayersCount()
return count
def loadList(layers):
for layer in layers:
QGisLayers.load(layer)

@staticmethod
def load(layer, name = None, crs = None):
prjSetting = None
settings = QSettings()
try:
if crs != None:
prjSetting = settings.value("/Projections/defaultBehaviour")
settings.setValue("/Projections/defaultBehaviour", QVariant(""))
if name == None:
name = path.split(layer)[1]
if layer.endswith("shp"):
qgslayer = QgsVectorLayer(layer, name, 'ogr')
if crs != None:
qgslayer.setCrs(crs, False)
QgsMapLayerRegistry.instance().addMapLayer(qgslayer)
else:
qgslayer = QgsRasterLayer(layer, name)
if crs != None:
qgslayer.setCrs(crs,False)
QgsMapLayerRegistry.instance().addMapLayer(qgslayer)
finally:
if prjSetting:
settings.setValue("/Projections/defaultBehaviour", prjSetting)


@staticmethod
def loadMap(layersmap, crs):
for name in layersmap.keys():
QGisLayers.load(layersmap[name], name, crs)


@staticmethod
def loadFromAlg(alg):
QGisLayers.loadMap(alg.getOuputsChannelsAsMap(), alg.crs)


@staticmethod
def getObjectFromUri(uri):
layers = QGisLayers.getRasterLayers()
for layer in layers:
if layer.dataProvider().dataSourceUri() == uri:
return layer
layers = QGisLayers.getVectorLayers()
for layer in layers:
if layer.dataProvider().dataSourceUri() == uri:
return layer





class LayersCount:

def __init__(self):
self.raster = 0
self.vector_point=0
self.vector_line=0
self.vector_polygon=0



@@ -1,5 +1,12 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui
from sextante.saga.SagaAlgorithmProvider import SagaAlgorithmProvider
from sextante.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider
import copy
from sextante.core.QGisLayers import QGisLayers
from sextante.gui.AlgorithmExecutor import AlgorithmExecutor, SilentProgress
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException

class Sextante:

@@ -52,23 +59,67 @@ def getAlgorithm(name):
return provider[name]
return None

##This methods are here to be used from the python console,
##making it easy to use SEXTANTE from there

@staticmethod
def algList():
def alglist(text=None):
s=""
for provider in Sextante.algs.values():
for alg in provider.values():
s+=(alg.name + " --->" + alg.commandLineName() + "\n")
sortedlist = sorted(provider.values(), key= lambda alg: alg.name)
for alg in sortedlist:
if text == None or text.lower() in alg.name.lower():
s+=(alg.name.ljust(50, "-") + "--->" + alg.commandLineName() + "\n")
print s

@staticmethod
def algHelp(name):
def alghelp(name):
alg = Sextante.getAlgorithm(name)
if alg != None:
print(str(alg))
else:
print "Algorithm not found"

@staticmethod
def runalg(name, *args):
alg = Sextante.getAlgorithm(name)
if alg == None:
print("Error: Algorithm not found\n")
return
if len(args) != len(alg.parameters) + len(alg.outputs):
print ("Error: Wrong number of parameters")
Sextante.alghelp(name)
return

alg = copy.deepcopy(alg)
i = 0
for param in alg.parameters:
if not param.setValue(args[i]):
print ("Error: Wrong parameter value: " + args[i])
return
i = i +1

for output in alg.outputs:
if not output.setChannel(args[i]):
print ("Error: Wrong output channel: " + args[i])
return
i = i +1

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

@staticmethod
def load(layer):
QGisLayers.load(layer)

@staticmethod
def getObject(string):
QGisLayers.getObjectFromUri(string)


@@ -3,8 +3,15 @@
from sextante.outputs.OutputTable import OutputTable
from sextante.outputs.OutputVector import OutputVector
from sextante.outputs.OutputRaster import OutputRaster
import datetime
class SextanteUtils:

NUM_EXPORTED = 1
LOG_ERROR = "ERROR"
LOG_INFO = "INFO"
LOG_WARNING = "WARNING"
LOG_ALGORITHM = "ALGORITHM"

@staticmethod
def userFolder():
userfolder = os.getenv('HOME') + os.sep + "sextante"
@@ -19,7 +26,7 @@ def softwareFolder():

@staticmethod
def isWindows():
return os.path =="nt"
return os.name =="nt"

@staticmethod
def tempFolder():
@@ -40,15 +47,65 @@ def setTempOutput(out):
else:
ext =""

filename = SextanteUtils.tempFolder() + os.sep + seconds + os.sep + ext
filename = SextanteUtils.tempFolder() + os.sep + seconds + str(SextanteUtils.NUM_EXPORTED) + ext
out.channel = filename
SextanteUtils.NUM_EXPORTED += 1


@staticmethod
def addToLog(msg):
pass
def logFilename():
batchfile = SextanteUtils.userFolder() + os.sep + "sextante_qgis.log"
return batchfile


@staticmethod
def addToLog(msgtype, msg):

if isinstance(msg, list):
text=""
for i in range(0, len(msg)):
text+=msg[i] + "|"
text = text[:-1]
else:
text = str(msg)
line = msgtype + "|" +str(datetime.datetime.now()) + "|" + text + "\n"
logfile = open(SextanteUtils.logFilename(), "a")
logfile.write(line)
logfile.close()

@staticmethod
def getLogEntries():
entries={}
errors=[]
algorithms=[]
warnings=[]
info=[]
lines = open(SextanteUtils.logFilename())
line = lines.readline()
while line != "":
line = line.strip("\n").strip()
tokens = line.split("|")
text=""
for i in range(2, len(tokens)):
text+=tokens[i] + "\n"
if line.startswith(SextanteUtils.LOG_ERROR):
errors.append(LogElement(tokens[1], text))
elif line.startswith(SextanteUtils.LOG_ALGORITHM):
algorithms.append(LogElement(tokens[1], text))
elif line.startswith(SextanteUtils.LOG_WARNING):
warnings.append(LogElement(tokens[1], text))
elif line.startswith(SextanteUtils.LOG_INFO):
info.append(LogElement(tokens[1], text))
lines.close()
entries[SextanteUtils.LOG_ERROR] = errors
entries[SextanteUtils.LOG_ALGORITHM] = algorithms
return entries

class LogElement():

def __init__(self, date, text):
self.date = date
self.text = text



0 comments on commit 2513431

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