[gdal-dev] Adding field to Shapefile via Python

Even Rouault even.rouault at mines-paris.org
Sun Mar 20 19:05:30 EDT 2011


Le dimanche 20 mars 2011 23:47:44, Mike Toews a écrit :
> Ok, I found the issue. Rather than adding a new field def'n:
> layer_defn.AddFieldDefn(new_field)
> 
> it needs to instead be created on the layer:
> layer.CreateField(new_field)
> 
> The documentation is misleading, as I thought I couldn't add a field
> to an existing shapefile if there were features in it. I would
> recommend adding a "See also" link from AddFieldDefn to:
> http://www.gdal.org/ogr/ogr__api_8h.html#ab585ef1166c61c4819f7fd46ee4a275
> 
Agreed, done in http://trac.osgeo.org/gdal/changeset/21999


More information about the gdal-dev mailing list