Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add unit test for processing polygonize algorithm
  • Loading branch information
nyalldawson committed Jan 31, 2017
1 parent 14bd79f commit 87f2fe5
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/plugins/processing/algs/qgis/Polygonize.py
Expand Up @@ -51,6 +51,7 @@ class Polygonize(GeoAlgorithm):
def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Polygonize')
self.group, self.i18n_group = self.trAlgorithm('Vector geometry tools')
self.tags = self.tr('create,lines,polygons,convert')
self.addParameter(ParameterVector(self.INPUT,
self.tr('Input layer'), [dataobjects.TYPE_VECTOR_LINE]))
self.addParameter(ParameterBoolean(self.FIELDS,
Expand Down
@@ -0,0 +1,21 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>polygonize_lines</Name>
<ElementPath>polygonize_lines</ElementPath>
<!--LINESTRING-->
<GeometryType>2</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>6</FeatureCount>
<ExtentXMin>-0.80000</ExtentXMin>
<ExtentXMax>0.80000</ExtentXMax>
<ExtentYMin>-0.40000</ExtentYMin>
<ExtentYMax>0.80000</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>id</Name>
<ElementPath>id</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
</GMLFeatureClass>
</GMLFeatureClassList>
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-0.8</gml:X><gml:Y>-0.4</gml:Y></gml:coord>
<gml:coord><gml:X>0.8</gml:X><gml:Y>0.8</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:polygonize_lines fid="polygonize_lines.0">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>-0.6,-0.4 -0.6,0.6 0.6,0.6</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:id>1</ogr:id>
</ogr:polygonize_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:polygonize_lines fid="polygonize_lines.1">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>-0.0,0.8 0,0</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:id>3</ogr:id>
</ogr:polygonize_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:polygonize_lines fid="polygonize_lines.2">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>0.2,0.4 -0.8,0.4</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:id>2</ogr:id>
</ogr:polygonize_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:polygonize_lines fid="polygonize_lines.3">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>-0.8,0.2 0.6,0.2 -0.8,-0.4</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:id>5</ogr:id>
</ogr:polygonize_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:polygonize_lines fid="polygonize_lines.4">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>0.8,0.6 0.8,0.0</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:id>4</ogr:id>
</ogr:polygonize_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:polygonize_lines fid="polygonize_lines.5">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>0.8,0.6 0.8,0.0</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:id>6</ogr:id>
</ogr:polygonize_lines>
</gml:featureMember>
</ogr:FeatureCollection>
26 changes: 26 additions & 0 deletions python/plugins/processing/tests/testdata/expected/polygonize.gfs
@@ -0,0 +1,26 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>polygonize</Name>
<ElementPath>polygonize</ElementPath>
<!--POLYGON-->
<GeometryType>3</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>3</FeatureCount>
<ExtentXMin>-0.60000</ExtentXMin>
<ExtentXMax>0.60000</ExtentXMax>
<ExtentYMin>-0.31429</ExtentYMin>
<ExtentYMax>0.60000</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>area</Name>
<ElementPath>area</ElementPath>
<Type>Real</Type>
</PropertyDefn>
<PropertyDefn>
<Name>perimeter</Name>
<ElementPath>perimeter</ElementPath>
<Type>Real</Type>
</PropertyDefn>
</GMLFeatureClass>
</GMLFeatureClassList>
35 changes: 35 additions & 0 deletions python/plugins/processing/tests/testdata/expected/polygonize.gml
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-0.6</gml:X><gml:Y>-0.3142857142857143</gml:Y></gml:coord>
<gml:coord><gml:X>0.6</gml:X><gml:Y>0.6</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:polygonize fid="polygonize.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-0.6,0.2 0.0,0.2 0.6,0.2 -0.6,-0.314285714285714 -0.6,0.2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:area>0.31</ogr:area>
<ogr:perimeter>3.02</ogr:perimeter>
</ogr:polygonize>
</gml:featureMember>
<gml:featureMember>
<ogr:polygonize fid="polygonize.1">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.0,0.2 -0.6,0.2 -0.6,0.4 0.0,0.4 0.0,0.2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:area>0.12</ogr:area>
<ogr:perimeter>1.60</ogr:perimeter>
</ogr:polygonize>
</gml:featureMember>
<gml:featureMember>
<ogr:polygonize fid="polygonize.2">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-0.6,0.4 -0.6,0.6 0.0,0.6 0.0,0.4 -0.6,0.4</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:area>0.12</ogr:area>
<ogr:perimeter>1.60</ogr:perimeter>
</ogr:polygonize>
</gml:featureMember>
</ogr:FeatureCollection>
13 changes: 13 additions & 0 deletions python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
Expand Up @@ -2299,3 +2299,16 @@ tests:
OUTPUT_LAYER:
name: expected/zonal_statistics.gml
type: vector

- algorithm: qgis:polygonize
name: Polygonize
params:
FIELDS: false
GEOMETRY: true
INPUT:
name: custom/polygonize_lines.gml
type: vector
results:
OUTPUT:
name: expected/polygonize.gml
type: vector

0 comments on commit 87f2fe5

Please sign in to comment.