[Qgis-user] Problem adding attribute value for a new feature...

luca_manganelli at comune.trento.it luca_manganelli at comune.trento.it
Wed Oct 14 07:45:47 PDT 2009


Hi to all, I'm using QGIS 1.3.0 and I have a problem setting an attribute
value to a postgis layer. I post the code:


ist = QgsMapLayerRegistry.instance()

# search for layer "test" in the list...
for name in ist.mapLayers():

  lay = ist.mapLayer (name)
  if (lay.name() == "testPostGIS"):

    # obtain the columnId of the field...
    columnIdx = lay.dataProvider().fieldNameIndex ("testCol")

    # start editing... and then create new feature
    lay.startEditing()
    feat = QgsFeature()
    feat.setGeometry (QgsGeometry.fromPoint(myPoint))

     # this below doesn't update value ...
     r = feat.addAttribute( columnIdx, QVariant(selTotem) )

     lay.addFeature (feat)
     lay.commitChanges ()


I see the point on the map, but the field value is still NULL. Why?




More information about the Qgis-user mailing list