I've added a new column to my table called "STRNAME" using:
path = "/Users/shapefiles/roads/"
metro_roads = QgsMapLayerRegistry.instance().mapLayersByName('Metro_roads')[0]
processing.runalg('qgis:addfieldtoattributestable', metro_roads, 'STRNAME', 2, 20, 0, path+"Metro_roads_new.shp")
Now I want to populate the new column with values. But I've looked for a processing algorithm (similar to "qgis.addfieldtoattributestable') and can't find one.
How can I add values to a table column from the Python Console?
Best Answer
You can actually do both (add a field and write values in it) using a single QGIS Processing algorithm:
This is what each parameter means:
If you want to add values for a field that was already added, just change the
new_field
parameter toFalse
: