I'm trying to programmatically populate a shp field with polygon areas:
import sys
import ogr
ds = ogr.Open( 'tttttttttt.shp', update = 1 )
if ds is None:
print "Open failed./n"
sys.exit( 1 )
lyr = ds.GetLayerByName( "tttttttttt" )
lyr.ResetReading()
field_defn = ogr.FieldDefn( "Area", ogr.OFTReal )
lyr.CreateField(field_defn)
for i in lyr:
# feat = lyr.GetFeature(i)
geom = i.GetGeometryRef()
area = geom.GetArea()
print 'Area =', area
lyr.SetFeature(i)
i.SetField( "Area", area )
ds = None
But I get an empty values in the field...