56
56
57
57
class GrassAlgorithm (GeoAlgorithm ):
58
58
59
+ GRASS_OUTPUT_TYPE_PARAMETER = "GRASS_OUTPUT_TYPE_PARAMETER"
59
60
GRASS_MIN_AREA_PARAMETER = "GRASS_MIN_AREA_PARAMETER"
60
61
GRASS_SNAP_TOLERANCE_PARAMETER = "GRASS_SNAP_TOLERANCE_PARAMETER"
61
62
GRASS_REGION_EXTENT_PARAMETER = "GRASS_REGION_PARAMETER"
62
63
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" ]
63
67
64
68
def __init__ (self , descriptionfile ):
65
69
GeoAlgorithm .__init__ (self )
@@ -113,17 +117,18 @@ def defineCharacteristicsFromFile(self):
113
117
line = lines .readline ().strip ("\n " ).strip ()
114
118
self .group = line
115
119
hasRasterOutput = False
116
- hasVectorOutput = False
120
+ hasVectorInput = False
121
+ vectorOutputs = 0
117
122
while line != "" :
118
123
try :
119
124
line = line .strip ("\n " ).strip ()
120
125
if line .startswith ("Parameter" ):
121
126
parameter = ParameterFactory .getFromString (line );
122
127
self .addParameter (parameter )
123
128
if isinstance (parameter , ParameterVector ):
124
- hasVectorOutput = True
129
+ hasVectorInput = True
125
130
if isinstance (parameter , ParameterMultipleInput ) and parameter .datatype < 3 :
126
- hasVectorOutput = True
131
+ hasVectorInput = True
127
132
elif line .startswith ("*Parameter" ):
128
133
param = ParameterFactory .getFromString (line [1 :])
129
134
param .isAdvanced = True
@@ -133,6 +138,8 @@ def defineCharacteristicsFromFile(self):
133
138
self .addOutput (output );
134
139
if isinstance (output , OutputRaster ):
135
140
hasRasterOutput = True
141
+ elif isinstance (output , OutputVector ):
142
+ vectorOutputs += 1
136
143
line = lines .readline ().strip ("\n " ).strip ()
137
144
except Exception ,e :
138
145
SextanteLog .addToLog (SextanteLog .LOG_ERROR , "Could not open GRASS algorithm: " + self .descriptionFile + "\n " + line )
@@ -142,15 +149,19 @@ def defineCharacteristicsFromFile(self):
142
149
self .addParameter (ParameterExtent (self .GRASS_REGION_EXTENT_PARAMETER , "GRASS region extent" ))
143
150
if hasRasterOutput :
144
151
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 :
146
153
param = ParameterNumber (self .GRASS_SNAP_TOLERANCE_PARAMETER , "v.in.ogr snap tolerance (-1 = no snap)" , - 1 , None , - 1.0 )
147
154
param .isAdvanced = True
148
155
self .addParameter (param )
149
156
param = ParameterNumber (self .GRASS_MIN_AREA_PARAMETER , "v.in.ogr min area" , 0 , None , 0.0001 )
150
157
param .isAdvanced = True
151
158
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
+
154
165
def getDefaultCellsize (self ):
155
166
cellsize = 0
156
167
for param in self .parameters :
@@ -251,7 +262,9 @@ def processAlgorithm(self, progress):
251
262
command += " res=" + str (cellsize );
252
263
else :
253
264
command += " res=" + str (self .getDefaultCellsize ())
254
-
265
+ alignToResolution = self .getParameterValue (self .GRASS_REGION_ALIGN_TO_RESOLUTION )
266
+ if alignToResolution :
267
+ command += " -a"
255
268
commands .append (command )
256
269
257
270
#2: set parameters and outputs
@@ -260,7 +273,8 @@ def processAlgorithm(self, progress):
260
273
if param .value == None or param .value == "" :
261
274
continue
262
275
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 ):
264
278
continue
265
279
if isinstance (param , (ParameterRaster , ParameterVector )):
266
280
value = param .value
@@ -321,11 +335,13 @@ def processAlgorithm(self, progress):
321
335
322
336
if isinstance (out , OutputVector ):
323
337
filename = out .value
324
- command = "v.out.ogr -ce input=" + out .name + uniqueSufix
338
+ command = "v.out.ogr -e input=" + out .name + uniqueSufix
325
339
command += " dsn=\" " + os .path .dirname (out .value ) + "\" "
326
340
command += " format=ESRI_Shapefile"
327
341
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
329
345
commands .append (command )
330
346
outputCommands .append (command )
331
347
0 commit comments