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

Pyqgis QgsFeature.setGeometry() causes crash #21654

Closed
qgib opened this issue Oct 15, 2015 · 1 comment
Closed

Pyqgis QgsFeature.setGeometry() causes crash #21654

qgib opened this issue Oct 15, 2015 · 1 comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Plugins

Comments

@qgib
Copy link
Contributor

qgib commented Oct 15, 2015

Author Name: Spencer Gardner (@spencerrecneps)
Original Redmine Issue: 13616
Affected QGIS version: 2.10.1
Redmine category:python_plugins


I'm getting a hard crash when I call setGeometry from the processing framework. I can't figure out why my code is failing but in any case QGIS shouldn't be crashing like this. Looks to be a segfault based on the log.

segfault at 0 ip 00007fc63a2a846a sp 00007fff34f66f00 error 6 in libqgis_core.so.2.10.1[7fc63a14d000+7ce000]

A few odd things:

  1. It doesn't crash all the time. The sample code below seems to crash about 80% of the time. But every once in a while it works without an issue. And when it works, I can run it again during the same session without problems. But if I restart QGIS it crashes again.
  2. I also tried using the WKT of the geometry in the sample below. If I construct the geom from the WKT there is no crash. For reference, the WKT of the sample feature is "LINESTRING(11897018 7014346,11897266 7014236)" - the SRID is 2283.

Sample code (from the Python console)

 #- note that roadsLayer is a PostGIS layer of type LINESTRING and primary key of "road_id")
 #- and the code grabs a geom from one of the road features by looking up the geom
 #- in a dictionary with keys of road_ids and values of geoms.
 #- I've chosen an arbitrary road_id to illustrate.
 
 #- imports
from qgis.core import *
from PyQt4.QtCore import QSettings, QVariant
from processing.tools import vector

 #- fields
fields = QgsFields()
fields.append(QgsField('field1', QVariant.Int))

 #- dict of road IDs and geoms (for convenience)
roads = dict()
for feat in vector.features(roadsLayer):
    roads[feat['road_id']] = feat.geometry()

 #- create the new feature
f = QgsFeature(fields)
f.setAttribute(0,0)
roadId = 6985
f.setGeometry(roads.get(roadId))

@qgib
Copy link
Contributor Author

qgib commented Oct 16, 2015

Author Name: Nyall Dawson (@nyalldawson)


Duplicate of #10836.

Solution is to alter this part of your script:

for feat in vector.features(roadsLayer):
roads[feat['road_id']] = feat.geometry()

to

for feat in vector.features(roadsLayer):
roads[feat['road_id']] = QgsGeometry(feat.geometry())


  • resolution was changed from to duplicate
  • status_id was changed from Open to Closed

@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Plugins labels May 25, 2019
@qgib qgib closed this as completed 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! Plugins
Projects
None yet
Development

No branches or pull requests

1 participant