Skip to content
Permalink
Browse files

[processing] tests for SAGA provider and related fixes

  • Loading branch information
alexbruy committed Nov 7, 2017
1 parent 057ab17 commit 4b63975eaf09119cfcbd0093aa4cc93ec8a27a39
@@ -152,14 +152,25 @@ def processAlgorithm(self, parameters, context, feedback):
if param.name() not in parameters or parameters[param.name()] is None:
continue

if parameters[param.name()].source().lower().endswith('sdat'):
self.exportedLayers[param.name()] = parameters[param.name()].source()[:-4] + 'sgrd'
if parameters[param.name()].source().lower().endswith('sgrd'):
self.exportedLayers[param.name()] = parameters[param.name()].source()
if isinstance(parameters[param.name()], str):
if parameters[param.name()].lower().endswith('sdat'):
self.exportedLayers[param.name()] = parameters[param.name()][:-4] + 'sgrd'
if parameters[param.name()].lower().endswith('sgrd'):
self.exportedLayers[param.name()] = parameters[param.name()]
else:
layer = self.parameterAsRasterLayer(parameters, param.name(), context)
exportCommand = self.exportRasterLayer(param.name(), layer)
if exportCommand is not None:
commands.append(exportCommand)
else:
exportCommand = self.exportRasterLayer(param.name(), parameters[param.name()])
if exportCommand is not None:
commands.append(exportCommand)
if parameters[param.name()].source().lower().endswith('sdat'):
self.exportedLayers[param.name()] = parameters[param.name()].source()[:-4] + 'sgrd'
if parameters[param.name()].source().lower().endswith('sgrd'):
self.exportedLayers[param.name()] = parameters[param.name()].source()
else:
exportCommand = self.exportRasterLayer(param.name(), parameters[param.name()])
if exportCommand is not None:
commands.append(exportCommand)
elif isinstance(param, QgsProcessingParameterFeatureSource):
if param.name() not in parameters or parameters[param.name()] is None:
continue
@@ -2,8 +2,8 @@ Shapes Buffer (Fixed distance)|Shapes Buffer
shapes_tools
QgsProcessingParameterFeatureSource|SHAPES|Shapes|-1|None|False
QgsProcessingParameterNumber|DIST_FIELD_DEFAULT|Buffer distance|QgsProcessingParameterNumber.Double|100.0|False|0.0|None
QgsProcessingParameterNumber|NZONES|Number of Buffer Zones|QgsProcessingParameterNumber.Double|1.0|False|1.0|None
QgsProcessingParameterNumber|NZONES|Number of Buffer Zones|QgsProcessingParameterNumber.Int|1|False|1|None
QgsProcessingParameterNumber|DARC|Arc Vertex Distance [Degree]|QgsProcessingParameterNumber.Double|5.0|False|0.01|45.0
QgsProcessingParameterBoolean|DISSOLVE |Dissolve Buffers|True
QgsProcessingParameterBoolean|POLY_INNER |Inner Buffer|False
QgsProcessingParameterVectorDestination|BUFFER|Buffer
QgsProcessingParameterBoolean|DISSOLVE|Dissolve Buffers|True
QgsProcessingParameterBoolean|POLY_INNER|Inner Buffer|False
QgsProcessingParameterVectorDestination|BUFFER|Buffer
@@ -667,7 +667,7 @@ def getParameterFromString(s):
params[5] = True if params[5].lower() == 'true' else False
elif clazz == QgsProcessingParameterNumber:
if len(params) > 2:
params[2] = QgsProcessingParameterNumber.Integer if params[2].lower().endswith('integer') else QgsProcessingParameterNumber.Double
params[2] = QgsProcessingParameterNumber.Integer if params[2].lower().endswith('int') else QgsProcessingParameterNumber.Double
if len(params) > 3:
params[3] = float(params[3].strip()) if params[3] is not None else 0
if len(params) > 4:
@@ -188,7 +188,10 @@ def load_result_param(self, param):
elif param['type'] == 'rasterhash':
outdir = tempfile.mkdtemp()
self.cleanup_paths.append(outdir)
basename = 'raster.tif'
if self.test_definition_file().lower().startswith('saga'):
basename = 'raster.sdat'
else:
basename = 'raster.tif'
filepath = os.path.join(outdir, basename)
return filepath

Binary file not shown.
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<SAGA_METADATA>
<HISTORY saga-version="2.3.1">
<MODULE library="shapes_tools" id="18" name="Shapes Buffer">
<OPTION type="table_field" id="DIST_FIELD" name="Buffer Distance" index="-1">&lt;not set&gt;</OPTION>
<OPTION type="double" id="DIST_FIELD_DEFAULT" name="Default">0.500000</OPTION>
<OPTION type="boolean" id="DISSOLVE" name="Dissolve Buffers">FALSE</OPTION>
<OPTION type="integer" id="NZONES" name="Number of Buffer Zones">1</OPTION>
<OPTION type="boolean" id="POLY_INNER" name="Inner Buffer">FALSE</OPTION>
<OPTION type="double" id="DARC" name="Arc Vertex Distance [Degree]">5.000000</OPTION>
<INPUT type="shapes" id="SHAPES" name="Shapes">
<FILE>/tmp/processing_bc2b178d0edf4b61beb3fbfde63b4e0a/c3630530c5804e2aa806438066037680/SHAPES.shp</FILE>
</INPUT>
<OUTPUT type="shapes" id="BUFFER" name="Buffer">SHAPES [Buffer]</OUTPUT>
</MODULE>
</HISTORY>
<SOURCE>
<FILE></FILE>
<DATABASE>
<FIELDS>
<FIELD TYPE="STRING">fid</FIELD>
<FIELD TYPE="STRING">name</FIELD>
<FIELD TYPE="LONGINT">intval</FIELD>
<FIELD TYPE="DOUBLE">floatval</FIELD>
</FIELDS>
</DATABASE>
<PROJECTION>
<OGC_WKT>GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]</OGC_WKT>
<PROJ4>+proj=longlat +a=6378137.000000 +b=6356752.314245 +no_defs</PROJ4>
<EPSG>-1</EPSG>
</PROJECTION>
</SOURCE>
<DESCRIPTION></DESCRIPTION>
</SAGA_METADATA>
@@ -0,0 +1 @@
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]
Binary file not shown.
Binary file not shown.
@@ -2,3 +2,29 @@

tests:

- algorithm: saga:invertgrid
name: Raster tools - Invert grid
params:
GRID:
name: dem.tif
type: raster
results:
INVERSE:
hash: 8e3947b878a00f70ce837fba962f6be6d3f0c8eae2d614099b015f1e
type: rasterhash

- algorithm: saga:fixeddistancebuffer
name: Vector general - Fixed distance buffer (polygon)
params:
DARC: 5.0
DISSOLVE: false
DIST_FIELD_DEFAULT: 0.5
NZONES: 1
POLY_INNER: false
SHAPES:
name: polys.gml
type: vector
results:
BUFFER:
name: expected/saga/buffer_polys.shp
type: vector

0 comments on commit 4b63975

Please sign in to comment.
You can’t perform that action at this time.