I'm trying to use QGIS to loop through a set of points, find their elevation from a DEM and use that value to update the point layer's attribute table. The loop works fine until I try to use changeAttributeValues(), and I can change the attribute values outside of the loop, but when I try to put the two together I cause a dump.
while provider.nextFeature(feat):
geom = feat.geometry()
x = geom.asPoint()
res, ident = rlayer.identify(QgsPoint(x))
for (k,v) in ident.iteritems():
elevation = float(v)
attrs = { 2 : elevation }
caps = vlayer.dataProvider().capabilities()
if caps & QgsVectorDataProvider.ChangeAttributeValues:
vlayer.dataProvider().changeAttributeValues({ fid : attrs })
This causes the following error in Linux:
*** glibc detected *** python2: free(): invalid pointer: 0x00000000024655b8 ***
Edit:
The problem isn't the loop, it is now I'm calling changeAttributeValues(). I've simplified the script down to just update a single point and it causes the same core dump. Here's the updated script:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from qgis.core import *
import qgis.utils
#initializes QGIS and points python to where it can find QGIS's stuff
QgsApplication.setPrefixPath("/usr/", True)
QgsApplication.initQgis()
vlayer = QgsVectorLayer("/gis/vector/elev_pts.shp", "elev_pts", "ogr")
if not vlayer.isValid():
print "Layer did not load!"
vlayer.dataProvider().changeAttributeValues({ 0: 2: 432.1 })
QgsApplication.exitQgis()
ifmeant to be inside thefor? – Nathan W Oct 02 '12 at 22:08