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
_______________________________________________
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer