Skip to content

Commit

Permalink
Added extra advanced options for GRASS algorithm Import/Export
Browse files Browse the repository at this point in the history
Modified/added some GRASS descriptions
  • Loading branch information
volaya committed May 2, 2013
1 parent 9ed5063 commit 4dfa972
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
36 changes: 26 additions & 10 deletions python/plugins/sextante/grass/GrassAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@

class GrassAlgorithm(GeoAlgorithm):

GRASS_OUTPUT_TYPE_PARAMETER = "GRASS_OUTPUT_TYPE_PARAMETER"
GRASS_MIN_AREA_PARAMETER = "GRASS_MIN_AREA_PARAMETER"
GRASS_SNAP_TOLERANCE_PARAMETER = "GRASS_SNAP_TOLERANCE_PARAMETER"
GRASS_REGION_EXTENT_PARAMETER = "GRASS_REGION_PARAMETER"
GRASS_REGION_CELLSIZE_PARAMETER = "GRASS_REGION_CELLSIZE_PARAMETER"
GRASS_REGION_ALIGN_TO_RESOLUTION = "-a_r.region"

OUTPUT_TYPES = ["auto", "point", "line", "area"]

def __init__(self, descriptionfile):
GeoAlgorithm.__init__(self)
Expand Down Expand Up @@ -113,17 +117,18 @@ def defineCharacteristicsFromFile(self):
line = lines.readline().strip("\n").strip()
self.group = line
hasRasterOutput = False
hasVectorOutput = False
hasVectorInput = False
vectorOutputs = 0
while line != "":
try:
line = line.strip("\n").strip()
if line.startswith("Parameter"):
parameter = ParameterFactory.getFromString(line);
self.addParameter(parameter)
if isinstance(parameter, ParameterVector):
hasVectorOutput = True
hasVectorInput = True
if isinstance(parameter, ParameterMultipleInput) and parameter.datatype < 3:
hasVectorOutput = True
hasVectorInput = True
elif line.startswith("*Parameter"):
param = ParameterFactory.getFromString(line[1:])
param.isAdvanced = True
Expand All @@ -133,6 +138,8 @@ def defineCharacteristicsFromFile(self):
self.addOutput(output);
if isinstance(output, OutputRaster):
hasRasterOutput = True
elif isinstance(output, OutputVector):
vectorOutputs += 1
line = lines.readline().strip("\n").strip()
except Exception,e:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + self.descriptionFile + "\n" + line)
Expand All @@ -142,15 +149,19 @@ def defineCharacteristicsFromFile(self):
self.addParameter(ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER, "GRASS region extent"))
if hasRasterOutput:
self.addParameter(ParameterNumber(self.GRASS_REGION_CELLSIZE_PARAMETER, "GRASS region cellsize (leave 0 for default)", 0, None, 0.0))
if hasVectorOutput:
if hasVectorInput:
param = ParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER, "v.in.ogr snap tolerance (-1 = no snap)", -1, None, -1.0)
param.isAdvanced = True
self.addParameter(param)
param = ParameterNumber(self.GRASS_MIN_AREA_PARAMETER, "v.in.ogr min area", 0, None, 0.0001)
param.isAdvanced = True
self.addParameter(param)


if vectorOutputs == 1:
param = ParameterSelection(self.GRASS_OUTPUT_TYPE_PARAMETER, "v.out.ogr output type", self.OUTPUT_TYPES)
param.isAdvanced = True
self.addParameter(param)


def getDefaultCellsize(self):
cellsize = 0
for param in self.parameters:
Expand Down Expand Up @@ -251,7 +262,9 @@ def processAlgorithm(self, progress):
command +=" res=" + str(cellsize);
else:
command +=" res=" + str(self.getDefaultCellsize())

alignToResolution = self.getParameterValue(self.GRASS_REGION_ALIGN_TO_RESOLUTION)
if alignToResolution:
command +=" -a"
commands.append(command)

#2: set parameters and outputs
Expand All @@ -260,7 +273,8 @@ def processAlgorithm(self, progress):
if param.value == None or param.value == "":
continue
if (param.name == self.GRASS_REGION_CELLSIZE_PARAMETER or param.name == self.GRASS_REGION_EXTENT_PARAMETER
or param.name == self.GRASS_MIN_AREA_PARAMETER or param.name == self.GRASS_SNAP_TOLERANCE_PARAMETER):
or param.name == self.GRASS_MIN_AREA_PARAMETER or param.name == self.GRASS_SNAP_TOLERANCE_PARAMETER
or param.name == self.GRASS_OUTPUT_TYPE_PARAMETER or param.name == self.GRASS_REGION_ALIGN_TO_RESOLUTION):
continue
if isinstance(param, (ParameterRaster, ParameterVector)):
value = param.value
Expand Down Expand Up @@ -321,11 +335,13 @@ def processAlgorithm(self, progress):

if isinstance(out, OutputVector):
filename = out.value
command = "v.out.ogr -ce input=" + out.name + uniqueSufix
command = "v.out.ogr -e input=" + out.name + uniqueSufix
command += " dsn=\"" + os.path.dirname(out.value) + "\""
command += " format=ESRI_Shapefile"
command += " olayer=" + os.path.basename(out.value)[:-4]
command += " type=auto"
typeidx = self.getParameterValue(self.GRASS_OUTPUT_TYPE_PARAMETER);
outtype = "auto" if typeidx is None else self.OUTPUT_TYPES[typeidx]
command += " type=" + outtype
commands.append(command)
outputCommands.append(command)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ r.resamp.interp - Resamples a raster map layer to a finer grid using interpolati
Raster (r.*)
ParameterRaster|input|Input raster layer|False
ParameterSelection|method|Interpolation method|nearest;bilinear;bicubic
ParameterBoolean|-a_r.region|Align region to resolution (default = align to bounds) in r.region|False
OutputRaster|output|Output raster layer
1 change: 1 addition & 0 deletions python/plugins/sextante/grass/description/r.resamp.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ ParameterRaster|input|Raster layer|False
ParameterNumber|ew_res|Desired east-west resolution|0.0|None|1
ParameterNumber|ns_res|Desired north-south resolution|0.0|None|1
ParameterBoolean|-t|Use dnorm independent tension|False
ParameterBoolean|-a_r.region|Align region to resolution (default = align to bounds) in r.region|False
OutputRaster|elev|Output layer
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ ParameterRaster|input|Input raster layer|False
ParameterSelection|method|Aggregation method|average;median;mode;minimum;maximum;quart1;quart3;perc90;sum;variance;stddev
ParameterBoolean|-n|Propagate NULLs|False
ParameterBoolean|-w|Weight according to area (slower)|False
ParameterBoolean|-a_r.region|Align region to resolution (default = align to bounds) in r.region|False
OutputRaster|output|Output raster layer
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
v.clean
v.clean.advanced - Toolset for cleaning topology of vector map (Advanced).
Vector (v.*)
ParameterVector|input|Layer to clean|-1|False
ParameterString|tool|Cleaning tools (comma separated)|break
ParameterNumber|thresh|Threshold|None|None|0.0
OutputVector|output|Cleaned vector layer
OutputVector|error|Errors layer
3 changes: 1 addition & 2 deletions python/plugins/sextante/grass/description/v.clean.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ 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.0
OutputVector|output|Cleaned vector layer
OutputVector|error|Errors layer

OutputVector|error|Errors layer

0 comments on commit 4dfa972

Please sign in to comment.