Skip to content

Commit

Permalink
improved r and saga behaviour, specially on linux; changed some grass…
Browse files Browse the repository at this point in the history
… descriptions

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@54 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed Mar 27, 2012
1 parent 9dbfabc commit 4dbb90e
Show file tree
Hide file tree
Showing 208 changed files with 2,207 additions and 1,912 deletions.
5 changes: 1 addition & 4 deletions build.xml
Expand Up @@ -2,14 +2,11 @@
<description>
SEXTANTE
</description>
<property name="version.number" value="0.1"/>

<property name="version.number" value="1.0"/>
<target name="copy"
description="copy files">

<copy todir="C:/Users/volaya/.qgis/python/plugins/sextante">
<fileset dir="src/sextante" includes="**"/>
</copy>

</target>
</project>
339 changes: 339 additions & 0 deletions license.txt

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/sextante/about/about.htm
@@ -1,13 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<title>SEXTANTE Spatial Data Analysis Library</title>
<title>SEXTANTE</title>
</head>
<body>
<img src="sextante_logo.png" />
<h2>SEXTANTE for QGIS</h2>
<p>SEXTANTE, a geoprocessing platform for QGIS</p>
<p>A development by Victor Olaya (volayaf@gmail.com)</p>
<p>A development by Victor Olaya (volayaf@gmail.com). Portions of this software by Michael Nimm and Carson Farmer</p>
<p>You are currently using SEXTANTE v1.0</p>
<p>This software is distributed under the terms of the GNU GPL License v2.
<p>For more information, please visit our website at <a href="http://sextantegis.com">http://sextantegis.com</a></p>
</body>
</html>
4 changes: 3 additions & 1 deletion src/sextante/core/AlgorithmProvider.py
Expand Up @@ -22,7 +22,9 @@ def loadAlgorithms(self):
#methods to be overridden.
#==============================

#Algorithm loading should take place here
#Algorithm loading should take place here, filling sefl.algs
#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

Expand Down
32 changes: 20 additions & 12 deletions src/sextante/core/GeoAlgorithm.py
Expand Up @@ -11,24 +11,30 @@
class GeoAlgorithm:

def __init__(self):
#parameters needed by the algorithm
self.parameters = list()
#outputs generated by the algorithm
self.outputs = list()
self.name = ""
self.group = ""
self.defineCharacteristics()
self.providerName = ""
#the crs taken from input layers (if possible), and used when loading output layers
self.crs = None
self.helpfile = None

#methods to overwrite when creating a custom geoalgorithm
#=========================================================
def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/alg.png")

def helpFile(self):
return None

def processAlgorithm(self):
'''here goes the algorithm itself'''
pass

def defineCharacteristics(self):
'''here is where the parameters and outputs should be filled'''
pass

#=========================================================
Expand All @@ -39,6 +45,7 @@ def execute(self, progress):
self.processAlgorithm(progress)

def resolveTemporaryOutputs(self):
'''sets temporary outputs (output.value = None) with a temporary file instead)'''
for out in self.outputs:
if out.value == None:
SextanteUtils.setTempOutput(out, self)
Expand Down Expand Up @@ -77,21 +84,28 @@ def setOutputValue(self, outputName, value):
if out.name == outputName:
out.value = value

def getVisibleOutputsCount(self):
'''returns the number of non-hidden outputs'''
i = 0;
for out in self.outputs:
if not out.hidden:
i+=1
return i;

def getOutputValuesAsDictionary(self):
d = {}
for out in self.outputs:
d[out.name] = out.value
return d

def canBeExecuted(self, layersCount):
return True

def __str__(self):
s = "ALGORITHM: " + self.name + "\n"
for param in self.parameters:
s+=("\t" + str(param) + "\n")
for out in self.outputs:
s+=("\t" + str(out) + "\n")
if not out.hidden:
s+=("\t" + str(out) + "\n")
s+=("\n")
return s

Expand All @@ -113,13 +127,6 @@ def getParameterFromName(self, name):
def getParameterValue(self, name):
for param in self.parameters:
if param.name == name:
#===============================================================
# if isinstance(param, ParameterNumber):
# return float(param.value)
# elif isinstance(param, ParameterBoolean):
# return param.value == str(True)
# else:
#===============================================================
return param.value
return None

Expand All @@ -131,6 +138,7 @@ def getOutputValue(self, name):


def getAsCommand(self):
'''Returns the command that would run this same algorithm from the console'''
s="Sextante.runalg(\"" + self.commandLineName() + "\","
for param in self.parameters:
s+=param.getValueAsCommandLineParameter() + ","
Expand Down
2 changes: 2 additions & 0 deletions src/sextante/core/QGisLayers.py
Expand Up @@ -7,6 +7,8 @@
import os.path

class QGisLayers:
'''This class contains method to communicate SEXTANTE with the QGIS interface,
mostly for retrieving layers and adding new ones to the QGIS canvas'''

ALL_TYPES = -1
iface = None;
Expand Down
34 changes: 21 additions & 13 deletions src/sextante/core/Sextante.py
Expand Up @@ -23,7 +23,7 @@ class Sextante:
iface = None
providers = [SagaAlgorithmProvider(), ScriptAlgorithmProvider(),
MMQGISAlgorithmProvider(), FToolsAlgorithmProvider(),
RAlgorithmProvider()]##, GrassAlgorithmProvider()]
RAlgorithmProvider()]#, GrassAlgorithmProvider()]
algs = {}
actions = {}
contextMenuActions = []
Expand Down Expand Up @@ -134,8 +134,10 @@ 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(text=None):
Expand Down Expand Up @@ -179,7 +181,7 @@ def runalg(name, *args):
if alg == None:
print("Error: Algorithm not found\n")
return
if len(args) != len(alg.parameters) + len(alg.outputs):
if len(args) != len(alg.parameters) + len(alg.getVisibleOutputsCount()):
print ("Error: Wrong number of parameters")
Sextante.alghelp(name)
return
Expand All @@ -193,10 +195,11 @@ def runalg(name, *args):
i = i +1

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

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

Expand All @@ -211,15 +214,19 @@ def runalg(name, *args):

@staticmethod
def load(layer):
'''loads a layer into QGIS'''
QGisLayers.load(layer)

@staticmethod
def loadFromAlg(layersdict):
'''load all layer resulting from a given algorithm.
Layers are passed as a dictionary, obtained from alg.getOutputValuesAsDictionary()'''
QGisLayers.loadFromDict(layersdict)

@staticmethod
def getObject(string):
QGisLayers.getObjectFromUri(string)
def getObject(uri):
'''Returns the QGIS object identified the given URI'''
QGisLayers.getObjectFromUri(uri)

@staticmethod
def runandload(name, *args):
Expand All @@ -229,7 +236,7 @@ def runandload(name, *args):
#in theory, this could not happen. Maybe we should show a message box?
QMessageBox.critical(None,"Error", "Error: Algorithm not found\n")
return
if len(args) != len(alg.parameters) + len(alg.outputs):
if len(args) != len(alg.parameters) + len(alg.getVisibleOutputsCount()):
QMessageBox.critical(None,"Error", "Error: Wrong number of parameters")
Sextante.alghelp(name)
return
Expand All @@ -243,10 +250,11 @@ def runandload(name, *args):
i = i +1

for output in alg.outputs:
if not output.setValue(args[i]):
QMessageBox.critical(None, "Error", "Error: Wrong output value: " + args[i])
return
i = i +1
if not output.hidden:
if not output.setValue(args[i]):
QMessageBox.critical(None, "Error", "Error: Wrong output value: " + args[i])
return
i = i +1

try:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
Expand Down
2 changes: 1 addition & 1 deletion src/sextante/ftools/copyright.txt
@@ -1,7 +1,7 @@
Copyright notice
-------------------

Algorithms in this folder have been adapted from the original ftools QGis plugin
Algorithms in this folder have been adapted from the original fTools QGis plugin
source code, by Carson Farmer, licensed under the terms of GNU GPL 2

For more info, please check http://www.ftools.ca/fTools.html
Expand Down
55 changes: 32 additions & 23 deletions src/sextante/grass/GrassAlgorithm.py
Expand Up @@ -28,7 +28,10 @@ def __init__(self, descriptionfile):
self.descriptionFile = descriptionfile
self.defineCharacteristicsFromFile()
self.numExportedLayers = 0
self.needsregion = False
#=======================================================================
# #true if the algorithms uses a region
# self.needsregion = False
#=======================================================================

def __deepcopy__(self,memo):
newone = GrassAlgorithm(self.descriptionFile)
Expand All @@ -38,6 +41,12 @@ def __deepcopy__(self,memo):
def getIcon(self):
return QIcon(os.path.dirname(__file__) + "/../images/grass.png")

def helpFile(self):
folder = SextanteConfig.getSetting(GrassUtils.GRASS_HELP_FOLDER)
if str(folder).strip() != "":
helpfile = str(folder) + os.sep + self.name + ".html"
return helpfile
return None
def defineCharacteristicsFromFile(self):
lines = open(self.descriptionFile)
line = lines.readline().strip("\n").strip()
Expand All @@ -49,8 +58,10 @@ def defineCharacteristicsFromFile(self):
line = line.strip("\n").strip()
if line.startswith("Parameter"):
self.addParameter(ParameterFactory.getFromString(line))
elif line.startswith("Region"):
self.needsregion = True
#===============================================================
# elif line.startswith("Region"):
# self.needsregion = True
#===============================================================
else:
self.addOutput(OutputFactory.getFromString(line))
line = lines.readline().strip("\n").strip()
Expand All @@ -64,8 +75,8 @@ def calculateResamplingExtent(self):
if auto:
first = True;
for param in self.parameters:
if isinstance(param, ParameterRaster):
if isinstance(param.value, QgsRasterLayer):
if isinstance(param, (ParameterRaster, ParameterVector)):
if isinstance(param.value, (QgsRasterLayer, QgsVectorLayer)):
value = param.value
else:
value = QGisLayers.getObjectFromUri(param.value)
Expand All @@ -83,35 +94,34 @@ def calculateResamplingExtent(self):
self.ymax = max(self.ymax, value.extent().yMaximum())
self.cellsize = max(self.cellsize, (value.extent().xMaximum() - value.extent().xMinimum())/value.getRasterXDim())
else:
self.xmin = SextanteConfig.getSetting(SagaUtils.SAGA_RESAMPLING_REGION_XMIN)
self.xmax = SextanteConfig.getSetting(SagaUtils.SAGA_RESAMPLING_REGION_XMAX)
self.ymin = SextanteConfig.getSetting(SagaUtils.SAGA_RESAMPLING_REGION_YMIN)
self.ymax = SextanteConfig.getSetting(SagaUtils.SAGA_RESAMPLING_REGION_YMAX)
self.cellsize = SextanteConfig.getSetting(SagaUtils.SAGA_RESAMPLING_REGION_CELLSIZE)
self.xmin = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_XMIN)
self.xmax = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_XMAX)
self.ymin = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_YMIN)
self.ymax = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_YMAX)
self.cellsize = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_CELLSIZE)


def processAlgorithm(self, progress):
path = GrassUtils.grassPath()
if path == "":
raise GeoAlgorithmExecutionException("GRASS folder is not configured.\nPlease configure it before running GRASS algorithms.")
useSelection = SextanteConfig.getSetting(SagaUtils.SAGA_USE_SELECTED)

commands = []
self.exportedLayers = {}
self.numExportedLayers = 0;

if self.needsregion:
self.calculateResamplingExtent()
##if self.needsregion:
self.calculateResamplingExtent()
GrassUtils.createTempMapset();

if self.needsregion:
command = "g.region"
command += " n=" + str(self.ymax)
command +=" s=" + str(self.ymin)
command +=" e=" + str(self.xmax)
command +=" w=" + str(self.xmin)
command +=" res=" + str(self.cellsize);
commands.append(command)
##if self.needsregion:
command = "g.region"
command += " n=" + str(self.ymax)
command +=" s=" + str(self.ymin)
command +=" e=" + str(self.xmax)
command +=" w=" + str(self.xmin)
command +=" res=" + str(self.cellsize);
commands.append(command)

#1: Export layer to grass mapset
for param in self.parameters:
Expand All @@ -138,8 +148,7 @@ def processAlgorithm(self, progress):
commands.append(self.exportRasterLayer(layer))
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
for layer in layers:
if (not value.endswith("shp")) or useSelection:
commands.append(self.exportRasterLayer(layer))
commands.append(self.exportVectorLayer(layer))

#2: set parameters and outputs
command = self.name
Expand Down

0 comments on commit 4dbb90e

Please sign in to comment.