Skip to content

Commit 4dfa972

Browse files
committedMay 2, 2013
Added extra advanced options for GRASS algorithm Import/Export
Modified/added some GRASS descriptions
1 parent 9ed5063 commit 4dfa972

File tree

6 files changed

+38
-12
lines changed

6 files changed

+38
-12
lines changed
 

‎python/plugins/sextante/grass/GrassAlgorithm.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@
5656

5757
class GrassAlgorithm(GeoAlgorithm):
5858

59+
GRASS_OUTPUT_TYPE_PARAMETER = "GRASS_OUTPUT_TYPE_PARAMETER"
5960
GRASS_MIN_AREA_PARAMETER = "GRASS_MIN_AREA_PARAMETER"
6061
GRASS_SNAP_TOLERANCE_PARAMETER = "GRASS_SNAP_TOLERANCE_PARAMETER"
6162
GRASS_REGION_EXTENT_PARAMETER = "GRASS_REGION_PARAMETER"
6263
GRASS_REGION_CELLSIZE_PARAMETER = "GRASS_REGION_CELLSIZE_PARAMETER"
64+
GRASS_REGION_ALIGN_TO_RESOLUTION = "-a_r.region"
65+
66+
OUTPUT_TYPES = ["auto", "point", "line", "area"]
6367

6468
def __init__(self, descriptionfile):
6569
GeoAlgorithm.__init__(self)
@@ -113,17 +117,18 @@ def defineCharacteristicsFromFile(self):
113117
line = lines.readline().strip("\n").strip()
114118
self.group = line
115119
hasRasterOutput = False
116-
hasVectorOutput = False
120+
hasVectorInput = False
121+
vectorOutputs = 0
117122
while line != "":
118123
try:
119124
line = line.strip("\n").strip()
120125
if line.startswith("Parameter"):
121126
parameter = ParameterFactory.getFromString(line);
122127
self.addParameter(parameter)
123128
if isinstance(parameter, ParameterVector):
124-
hasVectorOutput = True
129+
hasVectorInput = True
125130
if isinstance(parameter, ParameterMultipleInput) and parameter.datatype < 3:
126-
hasVectorOutput = True
131+
hasVectorInput = True
127132
elif line.startswith("*Parameter"):
128133
param = ParameterFactory.getFromString(line[1:])
129134
param.isAdvanced = True
@@ -133,6 +138,8 @@ def defineCharacteristicsFromFile(self):
133138
self.addOutput(output);
134139
if isinstance(output, OutputRaster):
135140
hasRasterOutput = True
141+
elif isinstance(output, OutputVector):
142+
vectorOutputs += 1
136143
line = lines.readline().strip("\n").strip()
137144
except Exception,e:
138145
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + self.descriptionFile + "\n" + line)
@@ -142,15 +149,19 @@ def defineCharacteristicsFromFile(self):
142149
self.addParameter(ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER, "GRASS region extent"))
143150
if hasRasterOutput:
144151
self.addParameter(ParameterNumber(self.GRASS_REGION_CELLSIZE_PARAMETER, "GRASS region cellsize (leave 0 for default)", 0, None, 0.0))
145-
if hasVectorOutput:
152+
if hasVectorInput:
146153
param = ParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER, "v.in.ogr snap tolerance (-1 = no snap)", -1, None, -1.0)
147154
param.isAdvanced = True
148155
self.addParameter(param)
149156
param = ParameterNumber(self.GRASS_MIN_AREA_PARAMETER, "v.in.ogr min area", 0, None, 0.0001)
150157
param.isAdvanced = True
151158
self.addParameter(param)
152-
153-
159+
if vectorOutputs == 1:
160+
param = ParameterSelection(self.GRASS_OUTPUT_TYPE_PARAMETER, "v.out.ogr output type", self.OUTPUT_TYPES)
161+
param.isAdvanced = True
162+
self.addParameter(param)
163+
164+
154165
def getDefaultCellsize(self):
155166
cellsize = 0
156167
for param in self.parameters:
@@ -251,7 +262,9 @@ def processAlgorithm(self, progress):
251262
command +=" res=" + str(cellsize);
252263
else:
253264
command +=" res=" + str(self.getDefaultCellsize())
254-
265+
alignToResolution = self.getParameterValue(self.GRASS_REGION_ALIGN_TO_RESOLUTION)
266+
if alignToResolution:
267+
command +=" -a"
255268
commands.append(command)
256269

257270
#2: set parameters and outputs
@@ -260,7 +273,8 @@ def processAlgorithm(self, progress):
260273
if param.value == None or param.value == "":
261274
continue
262275
if (param.name == self.GRASS_REGION_CELLSIZE_PARAMETER or param.name == self.GRASS_REGION_EXTENT_PARAMETER
263-
or param.name == self.GRASS_MIN_AREA_PARAMETER or param.name == self.GRASS_SNAP_TOLERANCE_PARAMETER):
276+
or param.name == self.GRASS_MIN_AREA_PARAMETER or param.name == self.GRASS_SNAP_TOLERANCE_PARAMETER
277+
or param.name == self.GRASS_OUTPUT_TYPE_PARAMETER or param.name == self.GRASS_REGION_ALIGN_TO_RESOLUTION):
264278
continue
265279
if isinstance(param, (ParameterRaster, ParameterVector)):
266280
value = param.value
@@ -321,11 +335,13 @@ def processAlgorithm(self, progress):
321335

322336
if isinstance(out, OutputVector):
323337
filename = out.value
324-
command = "v.out.ogr -ce input=" + out.name + uniqueSufix
338+
command = "v.out.ogr -e input=" + out.name + uniqueSufix
325339
command += " dsn=\"" + os.path.dirname(out.value) + "\""
326340
command += " format=ESRI_Shapefile"
327341
command += " olayer=" + os.path.basename(out.value)[:-4]
328-
command += " type=auto"
342+
typeidx = self.getParameterValue(self.GRASS_OUTPUT_TYPE_PARAMETER);
343+
outtype = "auto" if typeidx is None else self.OUTPUT_TYPES[typeidx]
344+
command += " type=" + outtype
329345
commands.append(command)
330346
outputCommands.append(command)
331347

‎python/plugins/sextante/grass/description/r.resamp.interp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ r.resamp.interp - Resamples a raster map layer to a finer grid using interpolati
33
Raster (r.*)
44
ParameterRaster|input|Input raster layer|False
55
ParameterSelection|method|Interpolation method|nearest;bilinear;bicubic
6+
ParameterBoolean|-a_r.region|Align region to resolution (default = align to bounds) in r.region|False
67
OutputRaster|output|Output raster layer

‎python/plugins/sextante/grass/description/r.resamp.rst.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ ParameterRaster|input|Raster layer|False
55
ParameterNumber|ew_res|Desired east-west resolution|0.0|None|1
66
ParameterNumber|ns_res|Desired north-south resolution|0.0|None|1
77
ParameterBoolean|-t|Use dnorm independent tension|False
8+
ParameterBoolean|-a_r.region|Align region to resolution (default = align to bounds) in r.region|False
89
OutputRaster|elev|Output layer

‎python/plugins/sextante/grass/description/r.resamp.stats.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ ParameterRaster|input|Input raster layer|False
55
ParameterSelection|method|Aggregation method|average;median;mode;minimum;maximum;quart1;quart3;perc90;sum;variance;stddev
66
ParameterBoolean|-n|Propagate NULLs|False
77
ParameterBoolean|-w|Weight according to area (slower)|False
8+
ParameterBoolean|-a_r.region|Align region to resolution (default = align to bounds) in r.region|False
89
OutputRaster|output|Output raster layer
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
v.clean
2+
v.clean.advanced - Toolset for cleaning topology of vector map (Advanced).
3+
Vector (v.*)
4+
ParameterVector|input|Layer to clean|-1|False
5+
ParameterString|tool|Cleaning tools (comma separated)|break
6+
ParameterNumber|thresh|Threshold|None|None|0.0
7+
OutputVector|output|Cleaned vector layer
8+
OutputVector|error|Errors layer

‎python/plugins/sextante/grass/description/v.clean.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ ParameterVector|input|Layer to clean|-1|False
55
ParameterSelection|tool|Cleaning tool|break;snap;rmdangle;chdangle;rmbridge;chbridge;rmdupl;rmdac;bpol;prune;rmarea;rmline;rmsa
66
ParameterNumber|thresh|Threshold|None|None|0.0
77
OutputVector|output|Cleaned vector layer
8-
OutputVector|error|Errors layer
9-
8+
OutputVector|error|Errors layer

0 commit comments

Comments
 (0)
Please sign in to comment.