Skip to content
Permalink
Browse files

Improve test coverage for k-nearest neighbor concave hull

  • Loading branch information
rudivs committed Sep 14, 2018
1 parent 858cd26 commit fd728c0854458b7f317f51afd8460e78edad0aef
@@ -199,9 +199,10 @@ def processAlgorithm(self, parameters, context, feedback):
out_feature.setAttributes([0])
sink.addFeature(out_feature, QgsFeatureSink.FastInsert)
else:
raise QgsProcessingException('Error while creating concave hull.')
# the_hull returns None only when there are less than three points after cleaning
raise QgsProcessingException('At least three unique points are required to create a concave hull.')
else:
raise QgsProcessingException('At least three unique points are required to create a concave hull.')
raise QgsProcessingException('At least three points are required to create a concave hull.')

return {self.OUTPUT: dest_id}

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ points_duplicate.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-0.4127659574468086</gml:X><gml:Y>-0.1702127659574468</gml:Y></gml:coord>
<gml:coord><gml:X>0.1659574468085108</gml:X><gml:Y>0.2042553191489361</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:points_duplicate fid="points_duplicate.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>-0.412765957446809,0.204255319148936</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_duplicate>
</gml:featureMember>
<gml:featureMember>
<ogr:points_duplicate fid="points_duplicate.1">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.165957446808511,-0.170212765957447</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_duplicate>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="points_duplicate" type="ogr:points_duplicate_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="points_duplicate_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ knearest_concave_hull_lines.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-1</gml:X><gml:Y>-3</gml:Y></gml:coord>
<gml:coord><gml:X>11</gml:X><gml:Y>5</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:knearest_concave_hull_lines fid="knearest_concave_hull_lines.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,-3 7,-3 10,-3 10,1 11,5 3,3 2,2 1,-1 -1,-1 6,-3</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>0</ogr:id>
</ogr:knearest_concave_hull_lines>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="knearest_concave_hull_lines" type="ogr:knearest_concave_hull_lines_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="knearest_concave_hull_lines_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:PolygonPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="id" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ knearest_concave_hull_multipoints.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>0</gml:X><gml:Y>-5</gml:Y></gml:coord>
<gml:coord><gml:X>8</gml:X><gml:Y>3</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:knearest_concave_hull_multipoints fid="knearest_concave_hull_multipoints.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0,-5 7,-1 8,-1 5,2 3,3 2,2 1,1 0,-1 0,-5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>0</ogr:id>
</ogr:knearest_concave_hull_multipoints>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="knearest_concave_hull_multipoints" type="ogr:knearest_concave_hull_multipoints_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="knearest_concave_hull_multipoints_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:PolygonPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="id" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ knearest_concave_hull_polys.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-1</gml:X><gml:Y>-3</gml:Y></gml:coord>
<gml:coord><gml:X>10</gml:X><gml:Y>6</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:knearest_concave_hull_polys fid="knearest_concave_hull_polys.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,-3 10,-3 10,1 6,1 6,4 5,5 3,6 2,6 2,5 2,2 -1,3 -1,-1 2,-1 6,-3</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>0</ogr:id>
</ogr:knearest_concave_hull_polys>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="knearest_concave_hull_polys" type="ogr:knearest_concave_hull_polys_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="knearest_concave_hull_polys_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:PolygonPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="id" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
@@ -5327,7 +5327,7 @@ tests:
type: vector

- algorithm: qgis:knearestconcavehull
name: K-nearest Neighbour Concave Hull - Points (7)
name: K-nearest Neighbor Concave Hull - Points (k=7)
params:
KNEIGHBORS: 7
INPUT:
@@ -5339,7 +5339,7 @@ tests:
type: vector

- algorithm: qgis:knearestconcavehull
name: K-nearest Neighbour Concave Hull - Group by field
name: K-nearest Neighbor Concave Hull - Group by field
params:
FIELD: id2
INPUT:
@@ -5351,6 +5351,55 @@ tests:
name: expected/knearest_concave_hull_points_id2.gml
type: vector

- algorithm: qgis:knearestconcavehull
name: K-nearest Neighbor Concave Hull - Lines (k=3)
params:
INPUT:
name: lines.gml
type: vector
KNEIGHBORS: 3
results:
OUTPUT:
name: expected/knearest_concave_hull_lines.gml
type: vector

- algorithm: qgis:knearestconcavehull
name: K-nearest Neighbor Concave Hull - Polys (k=3)
params:
INPUT:
name: polys.gml
type: vector
KNEIGHBORS: 3
results:
OUTPUT:
name: expected/knearest_concave_hull_polys.gml
type: vector

- algorithm: qgis:knearestconcavehull
name: K-nearest Neighbor Concave Hull - MultiPoints (k=3)
params:
INPUT:
name: multipoints.gml
type: vector
KNEIGHBORS: 3
results:
OUTPUT:
name: expected/knearest_concave_hull_multipoints.gml
type: vector

- algorithm: qgis:knearestconcavehull
name: K-nearest Neighbor Concave Hull - Duplicate Points
params:
INPUT:
name: custom/points_duplicate.gml
type: vector
KNEIGHBORS: 3
results:
OUTPUT:
name: expected/failure.gml
type: vector
expectedException: true

- algorithm: native:swapxy
name: Swap XY coordinates
params:

0 comments on commit fd728c0

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