[gdal-dev] Is it possible to add new fields to a shapefile and populate then?
woodbri at swoodbridge.com
Mon Apr 3 19:05:58 PDT 2017
I have a shapefile(s) and I want to read the features, generate some
metrics about each feature and then add them to the that feature. I'm
using python and one obvious way to to in effect create a new shapefile
with the columns I need to add, then copy the existing shapefile to the
new one adding the additional metrics.
I wondering if I can add the new columns to the shapefile, then do a
read and update.
Pros and cons to these approaches? and how to do the later one if possible?
I looked at the python gdal/ogr cookbook and didn't this specific
example. But I thinking of something along the lines of:
1. open the dataset for read/write
2. layer.CreateField() to add the new fields
3. loop through the features in the layer
4. and use feature.SetField()
5. and feature = None to commit the changes
will this work?
This email has been checked for viruses by Avast antivirus software.
More information about the gdal-dev