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

QgsPoint.clone() not fully reliable? It's original QgsFeature may get corrupted? #28481

Closed
qgib opened this issue Nov 28, 2018 · 3 comments
Closed
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! PyQGIS Related to the PyQGIS API Regression Something which used to work, but doesn't anymore

Comments

@qgib
Copy link
Contributor

qgib commented Nov 28, 2018

Author Name: Juan Manuel Perez (@juanmpd)
Original Redmine Issue: 20661
Affected QGIS version: 3.5(master)
Redmine category:python_bindings_/_sipify


We have stumbled upon an strange problem and reproducible problem. We attach a plugin to reproduce it.

The problem arises in this circumstances:

  • We have a layer. We iterate over all its features, then over all their geometries, then all of their nodes (QgsPoints). To reproduce the problem, we use a layer with only a single polygon.
  • For each node, we create a new QgsFeature (in memory), and we assign it a new geometry initialized with a clone of the node (QgsPoint)
  • The original layer is not modified in any way, nor its features.
  • We then repeat the above steps. We may repeat it successfully but only for a limited and variable number of iterations.
  • Eventually, the process will break with an unexpected exception.

p=. iteration_screenshot.png

  • More precisely, the exception raises because eventually we get a PolygonGeometry QgsGeometry (as expected), but its actual geometry (geom.constGet()) is reported as a QgsPoint. Debugging, it looks as "<QgsPoint: MultiPolygon (...)>", as shown in the attached screenshots.

p=. debugging_screenshot.png

How to reproduce it

We have prepared a plugin to easily reproduce the issue. We have attached as 'issuePlugin.zip' to this bug report.
You only need to install it in QGis. Then, a toolbar with a spider will appear (see above screenshots). You only need to click this icon. A dialog will open, showing how the test iterates until the unexpected exception is raised.

We have tested it in Qgis 3.5 MASTER and 3.4.1.


@qgib
Copy link
Contributor Author

qgib commented Nov 28, 2018

Author Name: Juan Manuel Perez (@juanmpd)


For now, we use a simple workaround: not using QgsPoint.clone(), but creating a brand new QgsPoint (QgsPoint(nodo.x(), nodo.y()).
But we think such a strange behavior should need be reviewed, as it may lead to unexpected or unreliable results...

@qgib
Copy link
Contributor Author

qgib commented Nov 29, 2018

Author Name: Martin Dobias (@wonder-sk)


I can replicate on linux too.

Simplified code to reproduce the issue:

import sip
for i in range(50):
    geom = QgsGeometry.fromWkt("MULTIPOLYGON(((1 1, 1 2, 2 2, 2 1, 1 1)))")
    geomV2 = geom.constGet()
    if isinstance(geomV2, QgsPoint):
        print("WHAT??????!!!!!  " + hex(sip.unwrapinstance(geomV2)))
        
    pt = QgsGeometry.fromWkt("POINT( 3 4 )")
    pt_g = pt.constGet()
    pt_clone = pt_g.clone()
    pt_x = QgsGeometry(pt_clone)
    print("new pt  " + hex(sip.unwrapinstance(pt_clone)))
print("-----")

@qgib
Copy link
Contributor Author

qgib commented Feb 5, 2019

Author Name: Matthias Kuhn (@m-kuhn)


Issue fixed upstream with upcoming sip version 4.19.14.


  • resolution was changed from to up/downstream
  • status_id was changed from Open to Closed

@qgib qgib closed this as completed Feb 5, 2019
@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! PyQGIS Related to the PyQGIS API Regression Something which used to work, but doesn't anymore labels May 25, 2019
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! PyQGIS Related to the PyQGIS API Regression Something which used to work, but doesn't anymore
Projects
None yet
Development

No branches or pull requests

1 participant