Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QGIS crashes with QgsGeometry method on empty collection #36142

Closed
uclaros opened this issue May 2, 2020 · 2 comments · Fixed by #36351
Closed

QGIS crashes with QgsGeometry method on empty collection #36142

uclaros opened this issue May 2, 2020 · 2 comments · Fixed by #36351
Assignees
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption

Comments

@uclaros
Copy link
Contributor

uclaros commented May 2, 2020

Describe the bug
QGIS crashes when calling QgsGeometry::nearestPoint() on an empty collection QgsGeometry

How to Reproduce
On a python console run the following:

g=QgsGeometry.fromWkt('GeometryCollection EMPTY')
g.nearestPoint(QgsGeometry.fromWkt('Point (42  0)'))

QGIS and OS versions
81911c1 on Debian testing (geos 3.8.1) , 3.10.2 on windows (geos 3.8.0)

Additional context
the empty geometry collection also gives the following strange result:
Nanananananananan, Batman!

>>> QgsGeometry.fromWkt('GeometryCollection EMPTY').minimalEnclosingCircle()

(<QgsGeometry: Polygon ((nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan, nan nan))>, <QgsPointXY: POINT EMPTY>, 0.0)
@uclaros uclaros added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label May 2, 2020
@gioman gioman added the PyQGIS Related to the PyQGIS API label May 4, 2020
@uclaros
Copy link
Contributor Author

uclaros commented May 4, 2020

@gioman This is not a PyQGIS issue, the python snippet is just for easy reproduction. QgsGeos is probably responsible.

@gioman gioman removed the PyQGIS Related to the PyQGIS API label May 4, 2020
@obrix
Copy link

obrix commented May 11, 2020

I can reproduce those two bugs :

  • For the first one it seems to be an issue with the use of an invalid GEOSNearestPoints_r result. Should be fixed by avoiding calling it when the geometry is empty.

  • Second one comes from the fact minimalEnclosingCircle has an hidden default parameters for the size of the number of segments of the enclosing circle (36). What you see is a default invalid result for the minimalEnclosingCircle algorithm : an invalid 36 segments polygon . In this case I think it is preferable to also return a null geometry if the geometry on which we call the algorithm is empty.

@obrix obrix self-assigned this May 11, 2020
obrix pushed a commit to obrix/QGIS that referenced this issue May 11, 2020
…empty to avoid creating an invalid GEOSNearestPoints_r.

* In QgsGeometry minimalEnclosingCircle method : return a default QgsGeometry instead of a default 36 segments polygon with NaN value if the geometry is empty.

fix qgis#36142
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants