Skip to content

Commit 7da8d72

Browse files
committedAug 16, 2018
Fix null output for k greater than number of points in k-neighbour algorithm
- if k is greater than the number of points, use the number of points - if k <3 is provided, use 3 - remove unused as_polygon function
1 parent 0a1d3e7 commit 7da8d72

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed
 

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def initAlgorithm(self, config=None):
8888
QgsProcessingParameterNumber.Integer,
8989
defaultValue=3, minValue=3))
9090
self.addParameter(QgsProcessingParameterField(self.FIELD,
91-
self.tr('Field (optional, set if creating concave hulls by class)'),
91+
self.tr('Field (set if creating concave hulls by class)'),
9292
parentLayerParameterName=self.INPUT, optional=True))
9393
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Output layer'),
9494
QgsProcessing.TypeVectorPolygon))
@@ -359,20 +359,6 @@ def point_in_polygon_q(point, list_of_points):
359359
return inside
360360

361361

362-
def as_polygon(point_list):
363-
"""
364-
Returns the geometry described by *point_list* in as QgsGeometry
365-
366-
:param point_list: list of tuples (x, y)
367-
:return: QgsGeometry
368-
"""
369-
# create a list of QgsPoint() from list of point coordinate strings in *point_list*
370-
points = [QgsPoint(point[0], point[1]) for point in point_list]
371-
# create the polygon geometry from list of point geometries
372-
poly = QgsGeometry.fromPolygon([points])
373-
return poly
374-
375-
376362
def extract_points(geom):
377363
"""
378364
Generate list of QgsPoints from QgsGeometry *geom* ( can be point, line, or polygon )
@@ -445,11 +431,10 @@ def concave_hull(points_list, k):
445431
"""
446432
# return an empty list if not enough points are given
447433
if k > len(points_list):
448-
return None
434+
k = len(points_list)
449435

450436
# the number of nearest neighbors k must be greater than or equal to 3
451-
# kk = max(k, 3)
452-
kk = max(k, 2)
437+
kk = max(k, 3)
453438

454439
# delete duplicate points
455440
point_set = clean_list(points_list)

0 commit comments

Comments
 (0)
Please sign in to comment.