mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
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
This commit is contained in:
parent
0a1d3e7e87
commit
7da8d727d1
@ -88,7 +88,7 @@ class KNearestConcaveHull(QgisAlgorithm):
|
||||
QgsProcessingParameterNumber.Integer,
|
||||
defaultValue=3, minValue=3))
|
||||
self.addParameter(QgsProcessingParameterField(self.FIELD,
|
||||
self.tr('Field (optional, set if creating concave hulls by class)'),
|
||||
self.tr('Field (set if creating concave hulls by class)'),
|
||||
parentLayerParameterName=self.INPUT, optional=True))
|
||||
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Output layer'),
|
||||
QgsProcessing.TypeVectorPolygon))
|
||||
@ -359,20 +359,6 @@ def point_in_polygon_q(point, list_of_points):
|
||||
return inside
|
||||
|
||||
|
||||
def as_polygon(point_list):
|
||||
"""
|
||||
Returns the geometry described by *point_list* in as QgsGeometry
|
||||
|
||||
:param point_list: list of tuples (x, y)
|
||||
:return: QgsGeometry
|
||||
"""
|
||||
# create a list of QgsPoint() from list of point coordinate strings in *point_list*
|
||||
points = [QgsPoint(point[0], point[1]) for point in point_list]
|
||||
# create the polygon geometry from list of point geometries
|
||||
poly = QgsGeometry.fromPolygon([points])
|
||||
return poly
|
||||
|
||||
|
||||
def extract_points(geom):
|
||||
"""
|
||||
Generate list of QgsPoints from QgsGeometry *geom* ( can be point, line, or polygon )
|
||||
@ -445,11 +431,10 @@ def concave_hull(points_list, k):
|
||||
"""
|
||||
# return an empty list if not enough points are given
|
||||
if k > len(points_list):
|
||||
return None
|
||||
k = len(points_list)
|
||||
|
||||
# the number of nearest neighbors k must be greater than or equal to 3
|
||||
# kk = max(k, 3)
|
||||
kk = max(k, 2)
|
||||
kk = max(k, 3)
|
||||
|
||||
# delete duplicate points
|
||||
point_set = clean_list(points_list)
|
||||
|
Loading…
x
Reference in New Issue
Block a user