[gdal-dev] python ogr feature didn't save attributes

Even Rouault even.rouault at spatialys.com
Wed Jun 24 01:29:03 PDT 2015


Le mercredi 24 juin 2015 08:47:19, Luca Delucchi a écrit :
> On 23 June 2015 at 16:02, Even Rouault <even.rouault at spatialys.com> wrote:
> > Luca,
> 
> Hi Even,
> 
> >> I'm writing a function to cycle inside the feature and update a column
> >> of attribute table, if I print the feature with DumpReadable() I can
> >> see the right attributes but when the script finish the final
> >> shapefile has no attribute table, any idea?
> >> 
> >> This is the relevant part of code
> >> 
> >> featureDefn = lay0.GetLayerDefn()
> >> field = ogr.FieldDefn(out_col, ogr.OFTReal)
> >> featureDefn.AddFieldDefn(field)
> > 
> > As suggested in http://gdal.org/python/osgeo.ogr.FeatureDefn-
> > class.html#AddFieldDefn , you must call CreateField() on the layer object
> > instead.
> 
> Also if I'm creating a new vector, not updating the existing one?
> 
> Because I use the featureDefn when I create the new feature, if I
> understood well CreateField should be used only to create a new field
> in an existing layer

Yes, use CreateField() only to add a new field that didn't exist in the layer 
before. If it is already existing, just use the existing feature definition.

> 
> > Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list