Skip to content

Commit 4482c39

Browse files
committedSep 12, 2018
Add tests for k-neighbour concave hull
1 parent f3e2d26 commit 4482c39

File tree

7 files changed

+165
-6
lines changed

7 files changed

+165
-6
lines changed
 

‎python/plugins/processing/algs/qgis/KNearestConcaveHull.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ def euclidian_distance(point1, point2):
232232

233233
def nearest_points(list_of_points, point, k):
234234
"""
235-
Returns a list of the indices of the k closest neighbors from list_of_points to the specified point.
236-
                                The measure of proximity is the Euclidean distance. Internally, k becomes the minimum between the given value
237-
                                for k and the number of points in list_of_points
235+
Returns a list of the indices of the k closest neighbors from list_of_points to the specified point. The measure
236+
of proximity is the Euclidean distance. Internally, k becomes the minimum between the given value for k and the
237+
number of points in list_of_points
238238
239239
:param list_of_points: list of tuples
240240
:param point: tuple (x, y)
@@ -397,9 +397,9 @@ def extract_points(geom):
397397

398398
def sort_by_angle(list_of_points, last_point, last_angle):
399399
"""
400-
returns the points in list_of_points in descending order of angle to the last segment of the envelope,
401-
                                measured in a clockwise direction. Thus, the rightmost of the neighboring points is always selected. The first
402-
                                point of this list will be the next point of the envelope.
400+
returns the points in list_of_points in descending order of angle to the last segment of the envelope, measured
401+
in a clockwise direction. Thus, the rightmost of the neighboring points is always selected. The first point of
402+
this list will be the next point of the envelope.
403403
"""
404404
def getkey(item):
405405
return angle_difference(last_angle, angle(last_point, item))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ knearest_concave_hull_points_7.xsd"
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>0</gml:X><gml:Y>-5</gml:Y></gml:coord>
10+
<gml:coord><gml:X>8</gml:X><gml:Y>3</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:knearest_concave_hull_points_7 fid="knearest_concave_hull_points_7.0">
16+
<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>
17+
<ogr:id>0</ogr:id>
18+
</ogr:knearest_concave_hull_points_7>
19+
</gml:featureMember>
20+
</ogr:FeatureCollection>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="knearest_concave_hull_points_7" type="ogr:knearest_concave_hull_points_7_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="knearest_concave_hull_points_7_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:PolygonPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="id" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:integer">
22+
<xs:totalDigits value="10"/>
23+
</xs:restriction>
24+
</xs:simpleType>
25+
</xs:element>
26+
</xs:sequence>
27+
</xs:extension>
28+
</xs:complexContent>
29+
</xs:complexType>
30+
</xs:schema>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<GMLFeatureClassList>
2+
<GMLFeatureClass>
3+
<Name>knearest_concave_hull_points_id2</Name>
4+
<ElementPath>knearest_concave_hull_points_id2</ElementPath>
5+
<!--POINT-->
6+
<GeometryType>1</GeometryType>
7+
<SRSName>EPSG:4326</SRSName>
8+
<DatasetSpecificInfo>
9+
<FeatureCount>9</FeatureCount>
10+
<ExtentXMin>0.00000</ExtentXMin>
11+
<ExtentXMax>8.00000</ExtentXMax>
12+
<ExtentYMin>-5.00000</ExtentYMin>
13+
<ExtentYMax>3.00000</ExtentYMax>
14+
</DatasetSpecificInfo>
15+
<PropertyDefn>
16+
<Name>id</Name>
17+
<ElementPath>id</ElementPath>
18+
<Type>Integer</Type>
19+
</PropertyDefn>
20+
<PropertyDefn>
21+
<Name>id2</Name>
22+
<ElementPath>id2</ElementPath>
23+
<Type>Integer</Type>
24+
</PropertyDefn>
25+
</GMLFeatureClass>
26+
</GMLFeatureClassList>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ knearest_concave_hull_points_id2.xsd"
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>0</gml:X><gml:Y>-5</gml:Y></gml:coord>
10+
<gml:coord><gml:X>8</gml:X><gml:Y>2</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:knearest_concave_hull_points_id2 fid="knearest_concave_hull_points_id2.0">
16+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0,-5 7,-1 8,-1 2,2 0,-1 0,-5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
17+
<ogr:id>0</ogr:id>
18+
<ogr:id2>0</ogr:id2>
19+
</ogr:knearest_concave_hull_points_id2>
20+
</gml:featureMember>
21+
</ogr:FeatureCollection>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="knearest_concave_hull_points_id2" type="ogr:knearest_concave_hull_points_id2_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="knearest_concave_hull_points_id2_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:PolygonPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="id" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:integer">
22+
<xs:totalDigits value="10"/>
23+
</xs:restriction>
24+
</xs:simpleType>
25+
</xs:element>
26+
<xs:element name="id2" nillable="true" minOccurs="0" maxOccurs="1">
27+
<xs:simpleType>
28+
<xs:restriction base="xs:integer">
29+
<xs:totalDigits value="10"/>
30+
</xs:restriction>
31+
</xs:simpleType>
32+
</xs:element>
33+
</xs:sequence>
34+
</xs:extension>
35+
</xs:complexContent>
36+
</xs:complexType>
37+
</xs:schema>

‎python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5326,6 +5326,31 @@ tests:
53265326
name: expected/concave_hull_points_07.gml
53275327
type: vector
53285328

5329+
- algorithm: qgis:knearestconcavehull
5330+
name: K-nearest Neighbour Concave Hull - Points (7)
5331+
params:
5332+
KNEIGHBORS: 7
5333+
INPUT:
5334+
name: points.gml
5335+
type: vector
5336+
results:
5337+
OUTPUT:
5338+
name: expected/knearest_concave_hull_points_7.gml
5339+
type: vector
5340+
5341+
- algorithm: qgis:knearestconcavehull
5342+
name: K-nearest Neighbour Concave Hull - Group by field
5343+
params:
5344+
KNEIGHBORS: 3
5345+
FIELD: id2
5346+
INPUT:
5347+
name: points.gml
5348+
type: vector
5349+
results:
5350+
OUTPUT:
5351+
name: expected/knearest_concave_hull_points_id2.gml
5352+
type: vector
5353+
53295354
- algorithm: native:swapxy
53305355
name: Swap XY coordinates
53315356
params:

0 commit comments

Comments
 (0)
Please sign in to comment.