[Qgis-developer] QgsFeature addAttribute to writer
Bjorn Nyberg
bjorn.burr.nyberg at gmail.com
Sat Aug 17 01:35:15 PDT 2013
Hej,
Is it possible to add an attribute to the writer when writing a geometry? It would appear this would be possible as explained in the 1.8 docs here (http://www.qgis.org/pyqgis-cookbook/vector.html#writing-vector-layers). However when I attempt something similar in 2.0
I received the following errors
writer = QgsVectorFileWriter(Output, "CP1250", fields, layer.dataProvider().geometryType(),layer.crs(), "ESRI Shapefile")
fet = QgsFeature()
fet.addAttribute(0, QVariant(1))
AttributeError: 'QgsFeature' object has no attribute 'addAttribute'
fet.setAttributeMap( { 0 : QVariant(1) })
AttributeError: 'QgsFeature' object has no attribute 'setAttributeMap'
Currently I have a work around by creating a dictionary keyed by the feature id (i.e. corresponding to the order in which the geometries are created) and then looping through the layer a second time and updating the attributes. It appears that this second loop is unnecessary if I can write the attributes when writing the geometries to the QgsFeature().
Cheers,
Bjorn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20130817/04e170e9/attachment.html>
More information about the Qgis-developer
mailing list