Skip to content
Permalink
Browse files
Improving GRASS bindings and editing GASS descriptions
  • Loading branch information
volaya committed Dec 11, 2012
1 parent a2997be commit 7197a31
Show file tree
Hide file tree
Showing 74 changed files with 425 additions and 211 deletions.
@@ -2,5 +2,7 @@ FILE(GLOB PY_FILES *.py)
FILE(GLOB OTHER_FILES grass.txt)
FILE(GLOB DESCR_FILES description/*.txt)

ADD_SUBDIRECTORY(postproc)

PLUGIN_INSTALL(sextante grass ${PY_FILES} ${OTHER_FILES})
PLUGIN_INSTALL(sextante grass/description ${DESCR_FILES})
@@ -17,6 +17,9 @@
***************************************************************************
"""
import uuid
from sextante.outputs.OutputHTML import OutputHTML
import importlib
from PyQt4.uic.Compiler.qtproxies import QtGui

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@@ -116,6 +119,7 @@ def defineCharacteristicsFromFile(self):
self.name = line
line = lines.readline().strip("\n").strip()
self.group = line
hasRasterOutput = False
while line != "":
try:
line = line.strip("\n").strip()
@@ -126,15 +130,19 @@ def defineCharacteristicsFromFile(self):
param.isAdvanced = True
self.addParameter(param)
else:
self.addOutput(OutputFactory.getFromString(line))
output = OutputFactory.getFromString(line)
self.addOutput(output);
if isinstance(output, OutputRaster):
hasRasterOutput = True
line = lines.readline().strip("\n").strip()
except Exception,e:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + self.descriptionFile + "\n" + line)
raise e
lines.close()

self.addParameter(ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER, "GRASS region extent"))
self.addParameter(ParameterNumber(self.GRASS_REGION_CELLSIZE_PARAMETER, "GRASS region cellsize (leave 0 for default)", 0, None, 0.0))
if hasRasterOutput:
self.addParameter(ParameterNumber(self.GRASS_REGION_CELLSIZE_PARAMETER, "GRASS region cellsize (leave 0 for default)", 0, None, 0.0))


def getDefaultCellsize(self):
@@ -230,10 +238,12 @@ def processAlgorithm(self, progress):
command +=" s=" + str(regionCoords[2])
command +=" e=" + str(regionCoords[1])
command +=" w=" + str(regionCoords[0])
if self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER) == 0:
command +=" res=" + str(self.getDefaultCellsize())
cellsize = self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER)
if cellsize:
command +=" res=" + str(cellsize);
else:
command +=" res=" + str(self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER));
command +=" res=" + str(self.getDefaultCellsize())

commands.append(command)

#2: set parameters and outputs
@@ -268,7 +278,7 @@ def processAlgorithm(self, progress):
for out in self.outputs:
if isinstance(out, OutputFile):
command+=(" " + out.name + "=\"" + out.value + "\"");
else:
elif not isinstance(out, OutputHTML): #html files are not generated by grass, only by sextante to decorate grass output
#an output name to make sure it is unique if the session uses this algorithm several times
uniqueOutputName = out.name + uniqueSufix
command += (" " + out.name + "=" + uniqueOutputName)
@@ -310,24 +320,24 @@ def processAlgorithm(self, progress):
progress.setCommand(line)
loglines.append(line)
if SextanteConfig.getSetting(GrassUtils.GRASS_LOG_COMMANDS):
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
self.consoleOutput = GrassUtils.executeGrass(commands, progress, outputCommands);
self.postProcessResults();
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
self.consoleOutput = GrassUtils.executeGrass(commands, progress, outputCommands);
self.postProcessResults();
# if the session has been created outside of this algorithm, add the new GRASS layers to it
# otherwise finish the session
if existingSession:
GrassUtils.addSessionLayers(self.exportedLayers)
else:
GrassUtils.endGrassSession()

def postProcessResults(self):
name = self.commandLineName().replace('.','_')
try:
module = __import__ ('sextante.grass.postproc.' + name)
except ImportError:
def postProcessResults(self):
name = self.commandLineName().replace('.','_')[len('grass:'):]
try:
module = importlib.import_module('sextante.grass.postproc.' + name)
except ImportError:
return
if hasattr(module, 'postProcessResults'):
func = getattr(module,'postProcessResults')
if hasattr(module, 'postProcessResults'):
func = getattr(module,'postProcessResults')
func(self)

def exportVectorLayer(self, orgFilename):
@@ -133,7 +133,7 @@ def createGrassScript(commands):
#gisdbase = os.path.join(os.path.expanduser("~"), "sextante", "tempdata", "grassdata")
output.write("GISDBASE: " + gisdbase + "\n");
output.write("LOCATION_NAME: " + location + "\n");
output.write("MAPSET: PERMAMENT \n");
output.write("MAPSET: PERMANENT \n");
output.write("GRASS_GUI: text\n");
output.close()

@@ -1,7 +1,7 @@
r.average
r.average - Finds the average of values in a cover map within areas assigned the same category value in a user-specified base map.
r.average - Finds the average of values in a cover raster layer within areas assigned the same category value in a user-specified base layer.
Raster (r.*)
ParameterRaster|base|Name of base raster map|False
ParameterRaster|cover|Name of cover raster map|False
ParameterRaster|base|Base raster layer|False
ParameterRaster|cover|Cover raster layer|False
ParameterBoolean|-c|Cover values extracted from the category labels of the cover map|False
OutputRaster|output|Name for output raster map
OutputRaster|output|Average values
@@ -1,7 +1,7 @@
r.basins.fill
r.basins.fill - Generates watershed subbasins raster map.
Raster (r.*)
ParameterRaster|c_map|Name of input coded stream network raster map|False
ParameterRaster|t_map|Name of input thinned ridge network raster map|False
ParameterNumber|number|Number of passes through the dataset|None|None|0.0
OutputRaster|result|Name for output raster map
ParameterRaster|c_map|Input coded stream network raster layer|False
ParameterRaster|t_map|Input thinned ridge network raster layer|False
ParameterNumber|number|Number of passes through the dataset|None|None|1
OutputRaster|result|Watersheds
@@ -1,7 +1,7 @@
r.bilinear
r.bilinear - Bilinear interpolation utility for raster map layers.
Raster (r.*)
ParameterRaster|input|Name of input raster map|False
ParameterRaster|input|Input raster layer|False
ParameterNumber|north|Specific input value to be assigned to the north and/or south poles for longitude-latitude grids|None|None|0
ParameterNumber|east|Specific input value to be assigned to the north and/or south poles for longitude-latitude grids|None|None|0
OutputRaster|output|Name for output raster map
OutputRaster|output|Output raster layer
@@ -1,7 +1,7 @@
r.bitpattern
r.bitpattern - Compares bit patterns with a raster map.
Raster (r.*)
ParameterRaster|input|Name of input raster map|False
ParameterRaster|input|Input raster layer|False
ParameterString|pattern|Bit pattern position(s)|
ParameterString|patval|Bit pattern value|
OutputRaster|output|Name for output raster map
OutputRaster|output|Output raster layer
@@ -1,8 +1,8 @@
r.buffer
r.buffer - Creates a raster map layer showing buffer zones surrounding cells that contain non-NULL category values.
Raster (r.*)
ParameterRaster|input|Name of input raster map|False
ParameterRaster|input|Input raster layer|False
ParameterString|distances|Distance zone(s) (e.g. 100,200,300)|
ParameterSelection|units|Units of distance|meters;kilometers;feet;miles;nautmiles
ParameterBoolean|-z|Ignore zero (0) data cells instead of NULL cells|False
OutputRaster|output|Name for output raster map
OutputRaster|output|Buffer
@@ -1,10 +1,10 @@
r.carve
r.carve - Takes vector stream data, transforms it to raster and subtracts depth from the output DEM.
Raster (r.*)
ParameterRaster|rast|Name of input raster elevation map|False
ParameterVector|vect|Name of vector input map containing stream(s)|1|False
ParameterRaster|rast|Elevation|False
ParameterVector|vect|Vector layer containing stream(s)|1|False
ParameterNumber|width|Stream width (in meters). Default is raster cell width|None|None|1
ParameterNumber|depth|Additional stream depth (in meters)|None|None|1
ParameterBoolean|-n|No flat areas allowed in flow direction|False
OutputRaster|output|Name for output raster map
OutputVector|points|Name for output vector map for adjusted stream points
OutputRaster|output|Modified elevation
OutputVector|points|Adjusted stream points
@@ -1,6 +1,6 @@
r.clump
r.clump - Recategorizes data in a raster map by grouping cells that form physically discrete areas into unique categories.
Raster (r.*)
ParameterRaster|input|Name of input raster map|False
ParameterRaster|input|Input layer|False
ParameterString|title|Title for output raster map|
OutputRaster|output|Name for output raster map
OutputRaster|output|Recategorized layer
@@ -5,3 +5,4 @@ ParameterRaster|map1|Name of first raster map|False
ParameterRaster|map2|Name of second raster map|False
ParameterSelection|units|Unit of measure|c;p;x;y;a;h;k;m
ParameterBoolean|-w|Wide report, 132 columns (default: 80)|False
OutputHTML|html|Output report
@@ -1,13 +1,10 @@
r.composite
r.composite - Combines red, green and blue raster maps into a single composite raster map.
Raster (r.*)
ParameterRaster|red|Name of raster map to be used for <red>|False
ParameterRaster|green|Name of raster map to be used for <green>|False
ParameterRaster|blue|Name of raster map to be used for <blue>|False
ParameterRaster|red|Red|False
ParameterRaster|green|Green|False
ParameterRaster|blue|Blue|False
ParameterNumber|levels|Number of levels to be used for each component|1.0|256.0|32
ParameterNumber|lev_red|Number of levels to be used for <red>|1.0|256.0|32
ParameterNumber|lev_green|Number of levels to be used for <green>|1.0|256.0|32
ParameterNumber|lev_blue|Number of levels to be used for <blue>|1.0|256.0|32
ParameterBoolean|-d|Dither|False
ParameterBoolean|-c|Use closest color|False
OutputRaster|output|Name for output raster map
OutputRaster|output|Output RGB image
@@ -1,6 +1,7 @@
r.contour
r.contour.level - Create vector contour from raster at specified levels
Raster (r.*)
ParameterRaster|input|Name of input raster map|False
ParameterRaster|input|Input raster|False
ParameterString|levels|List of contour levels|
OutputVector|output|Name of output vector map
ParameterString|cut|Minimum number of points for a contour line (0 -> no limit)|0
OutputVector|output|Contours
@@ -1,8 +1,9 @@
r.contour
r.contour.step - Create vector contours from raster at specified steps
Raster (r.*)
ParameterRaster|input|Name of input raster map|False
ParameterRaster|input|Input raster|False
ParameterString|minlevel|Minimum contour level|0
ParameterString|maxlevel|Maximum contour level|10000
ParameterString|step|Increment between contour levels|100
OutputVector|output|Name of output vector map
ParameterString|cut|Minimum number of points for a contour line (0 -> no limit)|0
OutputVector|output|contours

This file was deleted.

@@ -1,9 +1,9 @@
r.cost
r.cost - Creates a raster map showing the cumulative cost of moving between different geographic locations on an input raster map whose cell category values represent cost.
r.cost - Creates a raster layer of cumulative cost of moving across a raster layer whose cell values represent cost.
Raster (r.*)
ParameterRaster|input|Name of raster map containing grid cell cost information|False
ParameterVector|start_points|Name of starting vector points map|0|False
ParameterVector|stop_points|Name of stop vector points map|0|False
ParameterRaster|input|Unit cost layer|False
ParameterVector|start_points|Start points|0|False
ParameterVector|stop_points|Stop points|0|False
ParameterBoolean|-k|Use the 'Knight's move'; slower, but more accurate|False
ParameterBoolean|-n|Keep null values in output raster map|False
OutputRaster|output|Name for output raster map
ParameterBoolean|-n|Keep null values in output raster layer|False
OutputRaster|output|Cumulative cost
@@ -1,5 +1,6 @@
r.covar
r.covar - Outputs a covariance/correlation matrix for user-specified raster map layer(s).
r.covar - Outputs a covariance/correlation matrix for user-specified raster layer(s).
Raster (r.*)
ParameterMultipleInput|map|Name of input raster map(s)|3.0|False
ParameterMultipleInput|map|Input layers|3.0|False
ParameterBoolean|-r|Print correlation matrix|True
OutputHTML|html|Covariance report
@@ -7,5 +7,5 @@ ParameterNumber|scale|Scaling factor for attribute column values|None|None|1.0
ParameterString|tolerance|Maximum distance between theoretical arc and polygon segments as multiple of buffer|0.01
ParameterBoolean|-s|Make outside corners straight|False
ParameterBoolean|-c|Don't make caps at the ends of polylines|False
OutputVector|output|Name for output vector map
OutputVector|output|Output buffer

@@ -6,5 +6,5 @@ ParameterString|distance|Buffer distance in map units|
ParameterString|tolerance|Maximum distance between theoretical arc and polygon segments as multiple of buffer|0.01
ParameterBoolean|-s|Make outside corners straight|False
ParameterBoolean|-c|Don't make caps at the ends of polylines|False
OutputVector|output|Name for output vector map
OutputVector|output|Output buffer

@@ -7,4 +7,5 @@ ParameterString|where|WHERE conditions of SQL statement without 'where' keyword|
ParameterSelection|algorithm|Algorithm to use for classification|int;std;qua;equ;dis
ParameterNumber|nbclasses|Number of classes to define|2.0|None|3
ParameterBoolean|-g|Print only class breaks (without min and max)|True
OutputHTML|html|Classification

@@ -1,9 +1,9 @@
v.clean
v.clean - Toolset for cleaning topology of vector map.
Vector (v.*)
ParameterVector|input|Name of input vector map|-1|False
ParameterVector|input|Layer to clean|-1|False
ParameterSelection|tool|Cleaning tool|break;snap;rmdangle;chdangle;rmbridge;chbridge;rmdupl;rmdac;bpol;prune;rmarea;rmline;rmsa
ParameterNumber|thresh|Threshold|None|None|0
OutputVector|output|Name for output vector map
OutputVector|error|Name for output map where errors are written
OutputVector|output|Cleaned vector layer
OutputVector|error|Errors layer

@@ -1,7 +1,7 @@
v.db.select
v.db.select - Prints vector map attributes
Vector (v.*)
ParameterVector|map|Name of input vector map |-1|False
ParameterVector|map|Input vector map |-1|False
ParameterNumber|layer|Layer Number|1|None|1
ParameterString|columns|Name of attribute column(s), comma separated|
ParameterBoolean|-c|Do not include column names in output|False
@@ -11,6 +11,6 @@ ParameterString|fs|Output field separator|,
*ParameterString|nv|Null value indicator|
*ParameterBoolean|-v|Vertical output (instead of horizontal)|False
*ParameterBoolean|-r|Print minimal region extent of selected vector features instead of attributes|False
ParameterString|file|Name for output file|
OutputFile|file|Output file|


@@ -4,5 +4,5 @@ Vector (v.*)
ParameterVector|input|Name of input vector map|0|False
ParameterBoolean|-r|Use only points in current region|True
ParameterBoolean|-l|Output triangulation as a graph (lines), not areas|True
OutputVector|output|Name for output vector map
OutputVector|output|Delaunay triangulation

@@ -1,7 +1,7 @@
v.dissolve
v.dissolve - Dissolves boundaries between adjacent areas sharing a common category number or attribute.
Vector (v.*)
ParameterVector|input|Name of input vector map|-1|False
ParameterVector|input|Input vector layer|-1|False
ParameterTableField|column|Name of column used to dissolve common boundaries|input
OutputVector|output|Name for output vector map
OutputVector|output|Dissolved layer

@@ -1,10 +1,10 @@
v.distance
v.distance.toattr - Finds the nearest element in vector map 'to' for elements in vector map 'from'.
Vector (v.*)
ParameterVector|from|Name of existing vector map (from)|0|False
ParameterVector|to|Name of existing vector map (to)|-1|False
ParameterVector|from|"from" input layer|0|False
ParameterVector|to|"to" input layer|-1|False
ParameterSelection|upload|Values describing the relation between two nearest features|to_attr
ParameterTableField|column|Column where values specified by 'upload' option will be uploaded|to
ParameterTableField|to_column|Column name of nearest feature|to
ParameterBoolean|-a|Calculate distances to all features within the threshold|False
OutputVector|output|Name for output vector map
OutputVector|output|Output layer
@@ -1,10 +1,10 @@
v.distance
v.distance - Finds the nearest element in vector map 'to' for elements in vector map 'from'.
Vector (v.*)
ParameterVector|from|Name of existing vector map (from)|0|False
ParameterVector|to|Name of existing vector map (to)|-1|False
ParameterVector|from|"from" input layer|0|False
ParameterVector|to|"to" input layer|-1|False
ParameterSelection|upload|Values describing the relation between two nearest features|cat;dist;to_x;to_y;to_along;to_angle
ParameterTableField|column|Column where values specified by 'upload' option will be uploaded|to
ParameterBoolean|-a|Calculate distances to all features within the threshold|False
OutputVector|output|Name for output vector map
OutputVector|output|Output layer

@@ -1,11 +1,11 @@
v.drape
v.drape - Converts vector map to 3D by sampling of elevation raster map.
Vector (v.*)
ParameterVector|input|Name of input vector map|-1|False
ParameterVector|input|Iput vector layer|-1|False
ParameterRaster|rast|Elevation raster map for height extraction|False
ParameterSelection|method|Sampling method|nearest;bilinear;cubic
ParameterString|scale|Scale factor for sampled raster values|1.0
ParameterString|where|WHERE conditions of SQL statement without 'where' keyword|
ParameterString|null_value|Vector Z value for unknown height|
OutputVector|output|Name for output vector map
OutputVector|output|Output layer

0 comments on commit 7197a31

Please sign in to comment.