From 4dfa97293dfbcdf233b7f3f388f7f07029b39bb1 Mon Sep 17 00:00:00 2001 From: Victor Olaya Date: Thu, 2 May 2013 23:53:03 +0200 Subject: [PATCH] Added extra advanced options for GRASS algorithm Import/Export Modified/added some GRASS descriptions --- .../plugins/sextante/grass/GrassAlgorithm.py | 36 +++++++++++++------ .../grass/description/r.resamp.interp.txt | 1 + .../grass/description/r.resamp.rst.txt | 1 + .../grass/description/r.resamp.stats.txt | 1 + .../grass/description/v.clean.advanced.txt | 8 +++++ .../sextante/grass/description/v.clean.txt | 3 +- 6 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 python/plugins/sextante/grass/description/v.clean.advanced.txt diff --git a/python/plugins/sextante/grass/GrassAlgorithm.py b/python/plugins/sextante/grass/GrassAlgorithm.py index 81d4391fa2eb..fb47487fee2d 100644 --- a/python/plugins/sextante/grass/GrassAlgorithm.py +++ b/python/plugins/sextante/grass/GrassAlgorithm.py @@ -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,7 +117,8 @@ 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() @@ -121,9 +126,9 @@ def defineCharacteristicsFromFile(self): 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) diff --git a/python/plugins/sextante/grass/description/r.resamp.interp.txt b/python/plugins/sextante/grass/description/r.resamp.interp.txt index dca7d73c0558..4c440ec3e6bc 100644 --- a/python/plugins/sextante/grass/description/r.resamp.interp.txt +++ b/python/plugins/sextante/grass/description/r.resamp.interp.txt @@ -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 diff --git a/python/plugins/sextante/grass/description/r.resamp.rst.txt b/python/plugins/sextante/grass/description/r.resamp.rst.txt index 8df523c663f5..7996bca2550b 100644 --- a/python/plugins/sextante/grass/description/r.resamp.rst.txt +++ b/python/plugins/sextante/grass/description/r.resamp.rst.txt @@ -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 diff --git a/python/plugins/sextante/grass/description/r.resamp.stats.txt b/python/plugins/sextante/grass/description/r.resamp.stats.txt index c16136e01222..fa7d6d7dc89c 100644 --- a/python/plugins/sextante/grass/description/r.resamp.stats.txt +++ b/python/plugins/sextante/grass/description/r.resamp.stats.txt @@ -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 diff --git a/python/plugins/sextante/grass/description/v.clean.advanced.txt b/python/plugins/sextante/grass/description/v.clean.advanced.txt new file mode 100644 index 000000000000..8fb7f3f83238 --- /dev/null +++ b/python/plugins/sextante/grass/description/v.clean.advanced.txt @@ -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 \ No newline at end of file diff --git a/python/plugins/sextante/grass/description/v.clean.txt b/python/plugins/sextante/grass/description/v.clean.txt index 368626dd90a5..09fd0d5d9f4e 100644 --- a/python/plugins/sextante/grass/description/v.clean.txt +++ b/python/plugins/sextante/grass/description/v.clean.txt @@ -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 \ No newline at end of file