Skip to content

Commit 7197a31

Browse files
committed
Improving GRASS bindings and editing GASS descriptions
1 parent a2997be commit 7197a31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+425
-211
lines changed

python/plugins/sextante/grass/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ FILE(GLOB PY_FILES *.py)
22
FILE(GLOB OTHER_FILES grass.txt)
33
FILE(GLOB DESCR_FILES description/*.txt)
44

5+
ADD_SUBDIRECTORY(postproc)
6+
57
PLUGIN_INSTALL(sextante grass ${PY_FILES} ${OTHER_FILES})
68
PLUGIN_INSTALL(sextante grass/description ${DESCR_FILES})

python/plugins/sextante/grass/GrassAlgorithm.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
***************************************************************************
1818
"""
1919
import uuid
20+
from sextante.outputs.OutputHTML import OutputHTML
21+
import importlib
22+
from PyQt4.uic.Compiler.qtproxies import QtGui
2023

2124
__author__ = 'Victor Olaya'
2225
__date__ = 'August 2012'
@@ -116,6 +119,7 @@ def defineCharacteristicsFromFile(self):
116119
self.name = line
117120
line = lines.readline().strip("\n").strip()
118121
self.group = line
122+
hasRasterOutput = False
119123
while line != "":
120124
try:
121125
line = line.strip("\n").strip()
@@ -126,15 +130,19 @@ def defineCharacteristicsFromFile(self):
126130
param.isAdvanced = True
127131
self.addParameter(param)
128132
else:
129-
self.addOutput(OutputFactory.getFromString(line))
133+
output = OutputFactory.getFromString(line)
134+
self.addOutput(output);
135+
if isinstance(output, OutputRaster):
136+
hasRasterOutput = True
130137
line = lines.readline().strip("\n").strip()
131138
except Exception,e:
132139
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + self.descriptionFile + "\n" + line)
133140
raise e
134141
lines.close()
135142

136143
self.addParameter(ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER, "GRASS region extent"))
137-
self.addParameter(ParameterNumber(self.GRASS_REGION_CELLSIZE_PARAMETER, "GRASS region cellsize (leave 0 for default)", 0, None, 0.0))
144+
if hasRasterOutput:
145+
self.addParameter(ParameterNumber(self.GRASS_REGION_CELLSIZE_PARAMETER, "GRASS region cellsize (leave 0 for default)", 0, None, 0.0))
138146

139147

140148
def getDefaultCellsize(self):
@@ -230,10 +238,12 @@ def processAlgorithm(self, progress):
230238
command +=" s=" + str(regionCoords[2])
231239
command +=" e=" + str(regionCoords[1])
232240
command +=" w=" + str(regionCoords[0])
233-
if self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER) == 0:
234-
command +=" res=" + str(self.getDefaultCellsize())
241+
cellsize = self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER)
242+
if cellsize:
243+
command +=" res=" + str(cellsize);
235244
else:
236-
command +=" res=" + str(self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER));
245+
command +=" res=" + str(self.getDefaultCellsize())
246+
237247
commands.append(command)
238248

239249
#2: set parameters and outputs
@@ -268,7 +278,7 @@ def processAlgorithm(self, progress):
268278
for out in self.outputs:
269279
if isinstance(out, OutputFile):
270280
command+=(" " + out.name + "=\"" + out.value + "\"");
271-
else:
281+
elif not isinstance(out, OutputHTML): #html files are not generated by grass, only by sextante to decorate grass output
272282
#an output name to make sure it is unique if the session uses this algorithm several times
273283
uniqueOutputName = out.name + uniqueSufix
274284
command += (" " + out.name + "=" + uniqueOutputName)
@@ -310,24 +320,24 @@ def processAlgorithm(self, progress):
310320
progress.setCommand(line)
311321
loglines.append(line)
312322
if SextanteConfig.getSetting(GrassUtils.GRASS_LOG_COMMANDS):
313-
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
314-
self.consoleOutput = GrassUtils.executeGrass(commands, progress, outputCommands);
315-
self.postProcessResults();
323+
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
324+
self.consoleOutput = GrassUtils.executeGrass(commands, progress, outputCommands);
325+
self.postProcessResults();
316326
# if the session has been created outside of this algorithm, add the new GRASS layers to it
317327
# otherwise finish the session
318328
if existingSession:
319329
GrassUtils.addSessionLayers(self.exportedLayers)
320330
else:
321331
GrassUtils.endGrassSession()
322332

323-
def postProcessResults(self):
324-
name = self.commandLineName().replace('.','_')
325-
try:
326-
module = __import__ ('sextante.grass.postproc.' + name)
327-
except ImportError:
333+
def postProcessResults(self):
334+
name = self.commandLineName().replace('.','_')[len('grass:'):]
335+
try:
336+
module = importlib.import_module('sextante.grass.postproc.' + name)
337+
except ImportError:
328338
return
329-
if hasattr(module, 'postProcessResults'):
330-
func = getattr(module,'postProcessResults')
339+
if hasattr(module, 'postProcessResults'):
340+
func = getattr(module,'postProcessResults')
331341
func(self)
332342

333343
def exportVectorLayer(self, orgFilename):

python/plugins/sextante/grass/GrassUtils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def createGrassScript(commands):
133133
#gisdbase = os.path.join(os.path.expanduser("~"), "sextante", "tempdata", "grassdata")
134134
output.write("GISDBASE: " + gisdbase + "\n");
135135
output.write("LOCATION_NAME: " + location + "\n");
136-
output.write("MAPSET: PERMAMENT \n");
136+
output.write("MAPSET: PERMANENT \n");
137137
output.write("GRASS_GUI: text\n");
138138
output.close()
139139

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
r.average
2-
r.average - Finds the average of values in a cover map within areas assigned the same category value in a user-specified base map.
2+
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.
33
Raster (r.*)
4-
ParameterRaster|base|Name of base raster map|False
5-
ParameterRaster|cover|Name of cover raster map|False
4+
ParameterRaster|base|Base raster layer|False
5+
ParameterRaster|cover|Cover raster layer|False
66
ParameterBoolean|-c|Cover values extracted from the category labels of the cover map|False
7-
OutputRaster|output|Name for output raster map
7+
OutputRaster|output|Average values
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
r.basins.fill
22
r.basins.fill - Generates watershed subbasins raster map.
33
Raster (r.*)
4-
ParameterRaster|c_map|Name of input coded stream network raster map|False
5-
ParameterRaster|t_map|Name of input thinned ridge network raster map|False
6-
ParameterNumber|number|Number of passes through the dataset|None|None|0.0
7-
OutputRaster|result|Name for output raster map
4+
ParameterRaster|c_map|Input coded stream network raster layer|False
5+
ParameterRaster|t_map|Input thinned ridge network raster layer|False
6+
ParameterNumber|number|Number of passes through the dataset|None|None|1
7+
OutputRaster|result|Watersheds
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
r.bilinear
22
r.bilinear - Bilinear interpolation utility for raster map layers.
33
Raster (r.*)
4-
ParameterRaster|input|Name of input raster map|False
4+
ParameterRaster|input|Input raster layer|False
55
ParameterNumber|north|Specific input value to be assigned to the north and/or south poles for longitude-latitude grids|None|None|0
66
ParameterNumber|east|Specific input value to be assigned to the north and/or south poles for longitude-latitude grids|None|None|0
7-
OutputRaster|output|Name for output raster map
7+
OutputRaster|output|Output raster layer
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
r.bitpattern
22
r.bitpattern - Compares bit patterns with a raster map.
33
Raster (r.*)
4-
ParameterRaster|input|Name of input raster map|False
4+
ParameterRaster|input|Input raster layer|False
55
ParameterString|pattern|Bit pattern position(s)|
66
ParameterString|patval|Bit pattern value|
7-
OutputRaster|output|Name for output raster map
7+
OutputRaster|output|Output raster layer
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
r.buffer
22
r.buffer - Creates a raster map layer showing buffer zones surrounding cells that contain non-NULL category values.
33
Raster (r.*)
4-
ParameterRaster|input|Name of input raster map|False
4+
ParameterRaster|input|Input raster layer|False
55
ParameterString|distances|Distance zone(s) (e.g. 100,200,300)|
66
ParameterSelection|units|Units of distance|meters;kilometers;feet;miles;nautmiles
77
ParameterBoolean|-z|Ignore zero (0) data cells instead of NULL cells|False
8-
OutputRaster|output|Name for output raster map
8+
OutputRaster|output|Buffer
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
r.carve
22
r.carve - Takes vector stream data, transforms it to raster and subtracts depth from the output DEM.
33
Raster (r.*)
4-
ParameterRaster|rast|Name of input raster elevation map|False
5-
ParameterVector|vect|Name of vector input map containing stream(s)|1|False
4+
ParameterRaster|rast|Elevation|False
5+
ParameterVector|vect|Vector layer containing stream(s)|1|False
66
ParameterNumber|width|Stream width (in meters). Default is raster cell width|None|None|1
77
ParameterNumber|depth|Additional stream depth (in meters)|None|None|1
88
ParameterBoolean|-n|No flat areas allowed in flow direction|False
9-
OutputRaster|output|Name for output raster map
10-
OutputVector|points|Name for output vector map for adjusted stream points
9+
OutputRaster|output|Modified elevation
10+
OutputVector|points|Adjusted stream points
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
r.clump
22
r.clump - Recategorizes data in a raster map by grouping cells that form physically discrete areas into unique categories.
33
Raster (r.*)
4-
ParameterRaster|input|Name of input raster map|False
4+
ParameterRaster|input|Input layer|False
55
ParameterString|title|Title for output raster map|
6-
OutputRaster|output|Name for output raster map
6+
OutputRaster|output|Recategorized layer

0 commit comments

Comments
 (0)