[Qgis-developer] iterating over fields an values API 2.0

PIERRE Sylvain sylvain.pierre at cg67.fr
Mon Feb 17 07:36:51 PST 2014


Hi,

I'm working on porting a standalone app from 1.8 to 2.0 API
When iterating over vector features like this:

fields = layer.pendingFields()
  field_names = [field.name() for field in fields]
  for elem in layer.getFeatures():
          atr = dict(zip(field_names, elem.attributes()))

returns this:
{PyQt4.QtCore.QString(u'off_set'): <PyQt4.QtCore.QVariant object at 0x05115C70>, PyQt4.QtCore.QString(u'code'): <PyQt4.QtCore.QVariant object at 0x05115BC8>, PyQt4.QtCore.QString(u'pk'): <PyQt4.QtCore.QVariant object at 0x05115C00>, PyQt4.QtCore.QString(u'id'): <PyQt4.QtCore.QVariant object at 0x05115B90>, PyQt4.QtCore.QString(u'annee'): <PyQt4.QtCore.QVariant object at 0x05115CA8>, PyQt4.QtCore.QString(u'id_anom'): <PyQt4.QtCore.QVariant object at 0x05115B58>, PyQt4.QtCore.QString(u'fk_position'): <PyQt4.QtCore.QVariant object at 0x05115C38>, PyQt4.QtCore.QString(u'resolu'): <PyQt4.QtCore.QVariant object at 0x05115CE0>}

Instead of tupple like u'off_set': 1 ...

Info here:
http://gis.stackexchange.com/questions/76364/how-to-get-field-names-in-pyqgis-2-0/86751#86751

What is missing to get "good" values?

Thanks
Sylvain


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20140217/e1c8d763/attachment.html>


More information about the Qgis-developer mailing list