Skip to content
Permalink
Browse files

Added extra advanced options for GRASS algorithm Import/Export

Modified/added some GRASS descriptions
  • Loading branch information
volaya committed May 2, 2013
1 parent 9ed5063 commit 4dfa97293dfbcdf233b7f3f388f7f07029b39bb1
@@ -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)
@@ -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
@@ -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)
@@ -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:
@@ -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
@@ -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
@@ -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)

@@ -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
@@ -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
@@ -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
@@ -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
@@ -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.
You can’t perform that action at this time.