[Qgis-developer] Fwd: Sextante (python geoprocessing tools)
Tim Sutton
tim at linfiniti.com
Tue Mar 25 06:39:19 EDT 2008
Hi All
Agustin Lobo forwarded this on to me - could be an interesting addition to
the emerging set of geoprocessing tools if anyone of you pythonistas can
work out how to integrate it nicely into QGIS???
Regards
Tim
---------- Forwarded message ----------
From: Agustin Lobo <Agustin.Lobo at ija.csic.es>
Date: 25/03/2008 06:44
Subject: Sextante
To: Tim Sutton <tim at linfiniti.com>
Tim,
do you know Sextante (http://www.sextantegis.com/)? It's a set of python
extensions for gvSIG, a second version of the set that the same author,
Victor Olaya, made for SAGA. It's pretty undocumented in english, but
you can browse the code (http://code.google.com/p/sextantegis/).
I wonder if Sextante could be included in QGIS through a plugin, it's
got a GNU General Public License v2.
The set of tools is excellent, but I cannot find a list from outside
the program, this html file is the only thing I'm able
to send you.
Agus
--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo at ija.csic.es
http://www.ija.csic.es/gt/obster
COMMAND-LINE INTERFACE
Sextante extensions can be run from within gvSIG using the corresponding
toolbox, and also from a command-line shell. To start the SEXTANTE shell,
just click on the shell icon and you will see something like this:
Commands are introduced in the text field at the bottom of the window.
Simply type a command and press Enter. Messages appear in the upper text
area.
Pressing the up arrow key will give you the previous command in the session
history, while the down arrow one will give you the next one. Typing
historyyou will see the whole session history in the messages text
area.
Since most operations need some kind of layers, a view is needed to take
those layers from or to add the resulting layers to. As in the case of the
extension manager, command line processes take their input from the last
active window before the command line interface was invoked. In most cases,
you should open a view and then start the shell, so you have a view to work
with.
New views can be created using the addviwe command, with the following
sintax
addview viewname[string]
We can switch from one view to another using the activeview command.
activeview viewname[string]
>From here on, we will see how to perform geographical analysis using the
command line shell. The first thing we need is some data:
OPENING DATA. BASIC OPERATIONS WITH DATA
To open a new data object (it can be a vector layer, a raster layer or a
table), use the command open. It has the following syntax (you can see this
help line by simply typing open with no arguments at all):
open filename[string]
Filename is the path to the file you want to open, and name is an identifier
that will be later used to refer to this data object. Filenames can use
absolute or relative paths. When using relative paths, you can use the
cd command
to move to the desired directory. The ls command is also available to list
the content of a directory, with the usual arguments.
All the file formats supported by gvSIG are supported as well from the
command line. There is no need to select the driver, since it is selected
automatically from the file extension
For example, the following lines will open a shapes layer, a raster layer
and a table.
C:\sextanteCmd$open c:\data\points.shp
C:\sextanteCmd$open c:\data\dem25.asc
C:\sextanteCmd$open c:\data\spatialCorrelation.dbf
Wilcards(*, ?) can be used in the usual way.
Of course, you can add new objects the usual way, using gvSIG buttons and
menus, and then work with them from the command line interface.
Information about data objects can be retrieved using the describe command.
to refer to an object, use the name that it has on the table of contents.
For instance:
>describe spatialCorrelation.dbf
Type: TableNumber of records: 156
Table fields: | Distance | I_Moran | c_Geary | Semivariance |
>describe points.shp
Type: Vector layer - Point
Number of entities: 300
Table fields: | ID | X | Y | SAND | SILT | CLAY | SOILTYPE | EXTRAPOLAT |
>describe dem25.asc
Type: Raster layer
X min: 262846.525725
X max: 277871.525725
Y min: 4454025.0
Y max: 4464275.0
Cellsize X: 25.0
Cellsize Y: 0.0
Rows: 410
Cols: 601
Data objects can be renamed using the rename command, with the following
sintax:
rename old name[String], new name[String]
For example, to change the name of the table from "spatialCorrelation.dbf"
to "spatialCorrelation", type
> rename spatialCorrelation.dbf, spatialCorrelation
Names are case sensitive.
If you are not going to use a data object anymore, you can use the
closecommand to eliminate it and free some memory. For instance:
close mdt25.asc
PERFORMING ANALYSIS
All the algorithms that can be run fron the gvSIG GUI can also be run from
the command-line shell. Each of them is identified by a command. A list of
them (in alfabetical order) can be displayed using the algs command.
C:\SextanteCmd$algs
acccost acccostanisotropic accflow
acv aggregate aggregationindex
ahp aspect buffer
cellbalance channelnetwork classstatistics
clipgrid closegaps closegapsnn
cluster constantgrid contourlines
convergence correlation costinroutes
countequalto countgreaterthan countlowerthan
covariancematrix crossclassification crosssections
ctvi curvatures density
distancematrix disttochannelnetwork diversity
dominance edgecontamination elevationreliefindex
fillsinks filterclumps flowlineprofile
fragmentation fragstatsarea fragstatsdiversity
fuzzify generaterandombernoulli generaterandomnormal
generaterandomuniform generateterrain gradientlines
gridbasicstats gridcalculator gridcompletion
gridfromfunction gridorientation gridsfromtableandgrid
heightoverchannelnetwork hillshade hypsometry
idw invertnodata isocrones
kerneldensity kriging kurtosis
lineardecrease locateallocate majority
maxvalue maxvaluegrid maxvalueuphill
meancenter meanvalue meanvalueuphill
median mediancenter mergegrids
minority minvalue minvaluegrid
multipleregression ndvi nearestneighbor
nnanalysis normalize nrvi
numberofclasses pdfbinomial pdfchisquared
pdfexponential pdfnormal pdfstudent
peakflowmaxplu polartorect predictivemodels
profile protectionindex pviperry
pviqi pvirichardson pviwalther
quadrat range rasterizevectorlayer
rastertopoints realarea reclassifyconsecutive
reclassifydisjoint reclassifyequalamplitude reclassifyequalarea
recttopolar regression ripleysk
savegrid semivariances skewness
slope slopelength solarradiation
sortraster spatialcorrelation strahlerorder
sumofcostfromallpoints surfacespecificpoints thresholdbuffer
topographicindices ttvi tvi
universalkriging upslopeareafrompoint variance
varianceradius vectorize visibility
visualexposure volume volumebetweengrids
watersheds
To know more about an algorithm, just type its name with no arguments. For
instance:
>accflow
Usage: accflow(DEM[Raster Layer]
WEIGHTS[Optional Raster Layer]
METHOD[Selection]
CONVERGENCE[Numerical Value]
FLOWACC [output raster layer])
Along with the name of the algorithm you will see a list of the parameters
needed to run it. Between square brackets, the type of each parameters is
shown.
Let's have a look at the different types of parameters and how to introduce
their corresponding values in order to run the algorithm
- [Raster Layer] or [Vector Layer] or [Table]. Simply type the name of
the data object. If the parameter is optional and you do not want to asign
a value to it, type #
- [Numerical value]. Just a numerical value like 345 or 3.1415. Type #
to use the default value.
- [Selection] Type the number corresponding to the desired option or #
to use the default option
- [String] Just a text string... Type # to use the default value
- [Boolean] Type either true or false. Or type # to use the default
value
- [Multiple selection - *data_type*] A group of data objects is needed
to run the module. You have to group them into one single parameter,
enclosing them between square brackets.
For example, for the maxvaluegrid algorithm
C:\SextanteCmd$maxvaluegrid
Usage: maxvaluegrid(INPUT[Multiple Input - Raster Layer]
NODATA[Boolean])
The following line shows a valid example:
C:\SextanteCmd$maxvaluegrid [lyr1, lyr2, lyr3], false
Of course, lyr1, lyr2, lyr3 must be valid raster layers, already loaded.
in the case of [Multiple Input - Band], each parameter is defined by a pair
of values (layer, band). For example, for the cluster algorithm
C:\SextanteCmd$cluster
Usage: cluster(INPUT[Multiple Input - Band]
NUMCLASS[Numerical Value])
The following is a valid example:
C:\SextanteCmd$cluster [lyr1, 1, lyr1, 2, lyr2, 2], 5
The algorithm will use 3 bands, two of them from lyr1 (bands 1 and 2), and
one from lyr2 (band 2).
- [Table Field from XXX]. Type the name of the field in the
corresponding vector layer or table.
- [Fixed table]. Simply type the values of al the cells separated by
commas. First value corresponds to row 1 and column 1, second value to row 1
column 2, and so on. There is no need to divide values by rows, since that
is done automatically by the parser.
- [Point]. The two coordinates of the point must be enclosed between
square brackets (i.e. [220345, 4453616])
Output layers (if the algorithm generates them), can be saved to a temporary
file using the # sign. If you want to save them permanently, type the output
filename. Both relatives and absolutes path.
File format is selected from the file extension. This works in the same way
as using the usual graphical interface of the algorithm. Please, refer to
the extension manager help to know more about output file formats and how to
set them.
If you try to run any algorithm that generates new raster layers, it will
generate them with a cellsize and extension automatically calculated upon
the input raster layers. This behaviour can be modified using the
autoextentcommand:
>autoextent
Usage: autoextent(true/false)
By default it is set to true. If, however, you want to define a particular
extent and cellsize for all the output raster layers, you can use the
extentcommand
>extent
Usage: extent(raster layer[string])
extent(vector layer[string], cellsize[double])
extent(x min[double], y min[double],
x max[double], y max[double],
cell size[double])
Type "autoextent" to use automatic extent fitting when possible
Setting a fixed extent automatically turns off the autoextent feature (it
has the same effect as typing autoextent false)
Some modules, such as interpolation ones, require the explicit definition of
output extent and cellsize, since there is no raster input upon which these
can be defined.
RUNNING SCRIPTS
Scripts can be run also from the command prompt, using the run command.
C:\SextanteCmd$run
Usage: run filename[string], parameter_1[string],
parameter_2[string]...parameter_n[string]
SEXTANTE will open the chosen file and execute the lines included in the it,
one by one. Lines starting with "//" will be ignored, so you can add
comments to your scripts.
Here is a little example, that will calculate the Topographic Wetness Index
(TWI; Beven and Kirby, 1979) from a DEM and save the result as
c:\data\twi.tif
open c:\data\dem25.asc
slope dem25.asc, 2, #
accflow dem25.asc, #, 2, #, #, #
gridcalculator log(Flow accumulation/25/Slope), c:\data\twi.tif
Asumming that the script is saved in a text file in C:\data\script.txt, you
can run it using the following line.
>run C:\data\script.txt
Additional arguments might be passed to the run command. These represent
parameters which have to be defined within the script as #1, #2, etc. Up to
9 parameters can be used. Before executing the script, the command will
substitute each #n with the corresponding argument passed to the run
command.
Help file written by Víctor Olaya
The content of this file is distributed under a Creative
Commons<http://creativecommons.org/licenses/by/2.5/es/>license
--
Tim Sutton
QGIS Project Steering Committee Member - Release Manager
Visit http://qgis.org for a great open source GIS
openModeller Desktop Developer
Visit http://openModeller.sf.net for a great open source ecological niche
modelling tool
Home Page: http://tim.linfiniti.com
Skype: timlinux
Irc: timlinux on #qgis at freenode.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20080325/3ddd84f4/attachment-0001.html
More information about the Qgis-developer
mailing list