1

I have a problem with a specific method in qgis 2.8, 2.12 and 2.12.1 on linux and mac (I have not idea if in windows this problem persists)

The example:

from qgis.core import *
from qgis.utils import iface
from ceamos.utils import *
from ceamos.config import *

def run_script(iface):

    #remove all layers
    clearAll(iface)

    lyr = QgsVectorLayer(project_path + '/qgis_data/area.shp',
                          'laflorida',
                          vectorLayerType.ogr)

    assert lyr.isValid()

    QgsMapLayerRegistry.instance().addMapLayers([lyr]) 
    geom = lyr.getFeatures().next().geometry()
    print geom # <qgis._core.QgsGeometry object at 0x7f3a08715510>

    print geom.contains(QgsPoint(0,0)) # RuntimeError: wrapped C/C++ object of type QgsGeometry has been deleted

Update 25-DIC-2015

I have changed the code to

from qgis.core import *
from qgis.utils import iface
from ceamos.utils import *
from ceamos.config import *

def run_script(iface):

    #remove all layers
    clearAll(iface)

    lyr = QgsVectorLayer(project_path + '/qgis_data/area.shp',
                          'laflorida',
                          vectorLayerType.ogr)

    assert lyr.isValid()

    QgsMapLayerRegistry.instance().addMapLayers([lyr]) 
    #geom = lyr.getFeatures().next().geometry()
    geom = QgsGeometry(lyr.getFeatures().next().geometry())
    print geom # <qgis._core.QgsGeometry object at 0x7f3a08715510>

    # RuntimeError: wrapped C/C++ object of type QgsGeometry has been deleted 
    #print geom.contains(QgsPoint(0,0)) #Segmentation fault

    feat = lyr.getFeatures().next() #Segmentation fault
    #print feat.geometry().contains(QgsPoint(0,0))

But in the line feat = lyr.getFeatures().next() I got a segmentation fault error (in mac and ubuntu 14.04)

0

Seems to be bug #777

Try

feat = lyr.getFeatures().next()
feat.geometry().contains(QgsPoint(0,0))
  • in have segmetation fault in the line geom = QgsGeometry(lyr.getFeatures().next().geometry()) – ljofre Dec 24 '15 at 16:52
  • Updated, does it work now? – Matthias Kuhn Dec 24 '15 at 17:11
  • with the update I have a segmentation fault in feat = lyr.getFeatures().next() – ljofre Dec 25 '15 at 6:00
  • I have update the post with your suggestions and the new error – ljofre Dec 26 '15 at 1:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.