[Qgis-developer] set attributes of a new feature

Siki Zoltan siki at agt.bme.hu
Sun Nov 16 05:39:09 PST 2014


Dear List Members,

i found the solution to my problem in the QGIS API.
An internal Python vaiable must be created:

fields = lay.dataProvider().fields()
feat.setFields(fields, True)

Zoltan

On Sat, 15 Nov 2014, Siki Zoltan wrote:

> 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
>


More information about the Qgis-developer mailing list