py-gdalogr-cookbook
py-gdalogr-cookbook copied to clipboard
Add example of updating existing feature values in a layer using SetFeature()
All the current examples of writing feature data are writing new layers.
However updating values in existing layers is a common use-case, and as I just did it for the first time, requires a few little tricks, I.E.:
Opening the shapefile with osgeo.ogr.Open(input_segments_fname, 1) # so it is writable.
Using the route_segments_lyr.SetFeature(route_segment) function, so any SetField() calls you make actually get written to the file.
See http://gis.stackexchange.com/questions/34505/how-to-programatically-populate-a-shapefile-field-with-polygon-areas-in-ogr for an example.