py-gdalogr-cookbook icon indicating copy to clipboard operation
py-gdalogr-cookbook copied to clipboard

Add example of updating existing feature values in a layer using SetFeature()

Open PatSunter opened this issue 10 years ago • 0 comments

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.

PatSunter avatar Apr 06 '14 06:04 PatSunter