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

Luca Delucchi lucadeluge at gmail.com
Tue Jun 23 23:47:19 PDT 2015


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

> Even
>


-- 
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org


More information about the gdal-dev mailing list