[gdal-dev] python ogr feature didn't save attributes
Luca Delucchi
lucadeluge at gmail.com
Tue Jun 23 06:49:07 PDT 2015
Hi devs,
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)
# loop through input layer
for inFeature in lay0:
volu = None
# create a new feature
outFeature = ogr.Feature(featureDefn)
# copy the attributes and set geometry
outFeature.SetFrom(inFeature)
spec = inFeature.GetField(str(specie))
diameter = inFeature.GetField(str(diam))
heig = inFeature.GetField(str(height))
if diameter > 85:
diameter = 85
if spec in ['fa', 'al']:
if diameter > 4.0091:
values = CODES[spec]
volu = formula_vol(values['a'], values['b'], values['c'],
values['d0'], diameter, heig)
elif spec in ['ab', 'ar', 'la', 'pc', 'pn', 'ps']:
if diameter > 3.69465:
values = CODES[spec]
volu = formula_vol(values['a'], values['b'], values['c'],
values['d0'], diameter, heig)
outFeature.SetField(out_col, volu)
outFeature.DumpReadable()
# add the feature to the output layer
outLayer.CreateFeature(outFeature)
outFeature = None
outLayer = None
outDS = None
and this one of outFeature.DumpReadable()
OGRFeature(20150304_AREEINV_trees):-1
nr_progr_P (Integer) = 25
AREAINV (Integer) = 155
DBH_cm (Real) = 55.500000000000000
Heigth_m (Real) = 33.600000000000001
H_m (Real) = (null)
EST_UTM32W (Real) = 635874.174400790012442
NORD_UTM32 (Real) = 5127869.940315400250256
G_m2 (Real) = 0.241922065000000
V/M (String) = V
Crown_A_m2 (Real) = (null)
NOTE (String) = (null)
RBH_m (Real) = 0.277500000000000
Abbr_SPECI (String) = ar
TIPOLOGIA (String) = pianta
SP_Latino (String) = Picea_abies
SP_Inglese (String) = Norway_spruce
prova_volume (Real) = 2.46353029399417
POINT (635874.174400790012442 5127869.940315400250256)
and this is the output of ogrinfo
Layer name: prova
Geometry: Point
Feature Count: 1630
Extent: (634916.793252, 5127012.958636) - (637692.035641, 5129718.805166)
Layer SRS WKT:
PROJCS["WGS_1984_UTM_Zone_32N",
GEOGCS["GCS_WGS_1984",
DATUM["WGS_1984",
SPHEROID["WGS_84",6378137,298.257223563]],
PRIMEM["Greenwich",0],
UNIT["Degree",0.017453292519943295]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",9],
PARAMETER["scale_factor",0.9996],
PARAMETER["false_easting",500000],
PARAMETER["false_northing",0],
UNIT["Meter",1]]
FID: Real (11.0)
thanks a lot
--
ciao
Luca
http://gis.cri.fmach.it/delucchi/
www.lucadelu.org
More information about the gdal-dev
mailing list