<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hej,</div><div>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 (<a href="http://www.qgis.org/pyqgis-cookbook/vector.html#writing-vector-layers">http://www.qgis.org/pyqgis-cookbook/vector.html#writing-vector-layers</a>). However when I attempt something similar in 2.0 </div><div>I received the following errors</div><div><br></div><div><div style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; "><!--StartFragment-->writer = QgsVectorFileWriter(Output, "CP1250", fields, layer.dataProvider().geometryType(),layer.crs(), "ESRI Shapefile")<!--EndFragment--></div></div><div><div style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; text-indent: 0px; "><!--StartFragment-->fet = QgsFeature()<!--EndFragment--></div></div>fet.addAttribute(0, QVariant(1)) <br>AttributeError: 'QgsFeature' object has no attribute 'addAttribute' <br>fet.setAttributeMap( { 0 : QVariant(1) }) <br>AttributeError: 'QgsFeature' object has no attribute 'setAttributeMap' <div><br></div><div>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().</div><div><br></div><div>Cheers,</div><div>Bjorn</div></body></html>