Skip to content

Concave Hull algorithm generates empty geometry #63868

@jfbourdon

Description

@jfbourdon

What is the bug or the crash?

The algorithm native:concavehull sometimes generates an empty geometry and doesn't display any warning/error about it. I originally had the bug with a layer containing 71 741 polygons from which all vertices (> 259 000 000) has been extracted in order to pass these to the algorithm. I managed to reduce the number of vertices required to replicate the bug to the only five seen below.

Steps to reproduce the issue

Note that if any of the five vertices is removed, the algorithm then produces a valid polygon.

coords = [
    (391884.69849999994039536, 5389058.28989999927580357),
    (377930, 5375085),
    (360682.86270000040531158, 5611698.33709999918937683),
    (360682.8551000002771616, 5611698.31880000047385693),
    (360682.8525000000372529, 5611698.31259999983012676),
]

lyr = QgsVectorLayer("point?crs=EPSG:2950", "lyr", "memory")
for x, y in coords:
    geom = QgsGeometry().fromWkt(f"Point ({x} {y})")
    fet = QgsFeature()
    fet.setGeometry(geom)
    lyr.dataProvider().addFeature(fet)

alpha = 0.9
concave = processing.run("native:concavehull", {
    'INPUT':lyr,
    'ALPHA':alpha,
    'HOLES':False,
    'NO_MULTIGEOMETRY':False,
    'OUTPUT':'TEMPORARY_OUTPUT'
    })["OUTPUT"]

feature = next( concave.getFeatures() )
print(f"alpha:{alpha} ->  Is empty? {feature.geometry().isEmpty()}")  # True, the polygon is empty

Using the same coordinates with shapely gives a GEOS Exception. Here again, if any of the five vertices is removed, the algorithm then produces a valid polygon.

import shapely
multi_point = shapely.MultiPoint(coords)
concave = shapely.concave_hull(multi_point, ratio=alpha)
print(concave)
# shapely.errors.GEOSException: IllegalArgumentException: Tri::getAdjacent - invalid index

Does native:concavehull relies on GEOS or is it independant? If it relies on it, it's then both an upstream bug and a QGIS bug in the sense that the user should still be warned that something went wrong.

Versions

QGIS 3.44.4
GEOS 3.13.1-CAPI-1.19.2
Windows 11 Enterprise 23H2

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugEither a bug report, or a bug fix. Let's hope for the latter!ProcessingRelating to QGIS Processing framework or individual Processing algorithmsgeos

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions