[Qgis-developer] set attributes of a new feature
Chris Crook
ccrook at linz.govt.nz
Sat Nov 15 13:43:07 PST 2014
HI Siki
You need to keep the fields() array as a python entity for the duration of the existence of the feature...
that is
feat=QgsFeature()
fields=lay.dataProvider().fields()
feat.setFields(fields,true)
feat['point_id']=xxx
Think this should work...
Cheers
Chris
________________________________________
From: Siki Zoltan [siki at agt.bme.hu]
Sent: 16 November 2014 03:21
To: qgis-developer at lists.osgeo.org
Subject: [Qgis-developer] set attributes of a new feature
Dear List Members,
i've got in trouble creating new point feature in a shape file using
python (QGIS 2.2 on Fedora):
feat = QgsFeature()
feat.setFields(lay.dataProvider().fields(), True)
feat.setAttribute(feat.fieldNameIndex('point_id'), xxx)
The fieldNameIndex call makes QGIS crash
QGIS died on signal 11[Thread debugging using libthread_db enabled]
[New Thread 0x7f60fe021700 (LWP 12981)]
0x00000034ef8ac30d in waitpid () from /lib64/libc.so.6
[Current thread is 1 (Thread 0x7f610488b860 (LWP 12980))]
#0 0x00000034ef8ac30d in waitpid () from /lib64/libc.so.6
No symbol table info available.
#1 0x000000000055d0d9 in qgisCrash(int) ()
No symbol table info available.
#2 <signal handler called>
No symbol table info available.
#3 0x00000000005bc8bb in QVector<QgsFields::Field>::count() const ()
No symbol table info available.
...
lay is a valid layer:
(Pdb) p lay.name()
u'coord_sample'
The feature has attributes:
(Pdb) len(feat.attributes())
6
but
(Pdb) p feat.attributes()
[None, None, None, None, None, None]
but
(Pdb) lay.dataProvider().fields()[0].name()
u'point_id'
How can I populate attributes of the new feature?
Thanks,
Zoltan
This message contains information, which may be in confidence and may be subject to legal privilege. If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message. If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info at linz.govt.nz) and destroy the original message. LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ. Thank You.
More information about the Qgis-developer
mailing list