[Qgis-user] Running script from Sextante toolbox

Jonas Sjögren jonas.sjo at gmail.com
Fri Jan 11 01:37:45 PST 2013


Hi,
I am trying to create a script to run from the Sextante toolbox in which a
model from the Sextante Modeler is included.
As result the script will create a flooded area (polygon) out from a water
level input and a DEM (raster). The script looks like

from sextante.core.QGisLayers import QGisLayers
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.modeler.ModelerAlgorithmProvider import
ModelerAlgorithmProvider
from sextante.modeler.ModelerAlgorithm import ModelerAlgorithm
from sextante.algs.SextanteAlgorithmProvider import
SextanteAlgorithmProvider
from sextante.saga.SagaAlgorithmProvider import SagaAlgorithmProvider
from sextante.saga.SagaAlgorithm import SagaAlgorithm
from sextante.script.ScriptAlgorithmProvider import
ScriptAlgorithmProvider
from sextante.script.ScriptAlgorithm import ScriptAlgorithm

#Definition of inputs and outputs
#==============================
##DEMTot=raster
##FloodedArea_0.7=output vector

#Algorithm body
#==============================
Sextante.runalg("Modeler:CalculateFloodedAreas", "DEMTot", 0.7, None,
FloodedArea_0.7)


The model works alright but when running the script I get the following
error:

Traceback (most recent call last):
File "C:/Users/Erik/.qgis//python/plugins\sextante\core\GeoAlgorithm.py",
line 118, in execute
self.processAlgorithm(progress)
 File
"C:/Users/Erik/.qgis//python/plugins\sextante\script\ScriptAlgorithm.py",
line 216, in processAlgorithm
exec(script) in ns
File "<string>", line 19
Sextante.runalg("Modeler:CalculateFloodedAreas", "DEMTot", 0.7, None,
FloodedArea_0.7)

  ^
SyntaxError: invalid syntax

As a beginner of Python I have to stick to examples provided, but
unfortunately I have not found many run from the Sextante toolbox. In
http://documentation.qgis.org/html/en/user_manual/sextante/console.html I
have found the following example:
##dem=raster
##twi=output

ret_slope = Sextante.runalg("saga:slopeaspectcurvature", dem, 0, None,
None, None, None, None)
ret_area = Sextante.runalg("saga:catchmentarea(mass-fluxmethod)", "dem", 0,
False, False, False, False, None, None, None, None, None)

Sextante.runalg("saga:topographicwetnessindex(twi), ret_slope['SLOPE'],
ret_area['AREA'], None, 1, 0, twi)

However, I believe there is something missing here. Shouldn´t there be
some definitions of imports? Pathways?

 Anybody who could give me some hints on where to find good examples or tip
to get me on the right track? I´m running QGIS on Windows.
Thanks in advance,
Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20130111/cb09730c/attachment.html>


More information about the Qgis-user mailing list