You need to call lyr.SetFeature(feat) before your call to lyr.GetNextFeature()
HTH, HAND Francis On 14 July 2010 11:11, Joel C <[email protected]> wrote: > Hello, i'm new here and I am attempting to modify attributes of a > shapefile via python I can't seem to get the shapefile to be > updated! Can anyone tell me what i'm doing wrong? > > import sys > import osgeo.ogr as ogr > import random > > ds = ogr.Open( "dist_google.shp", 1 ) > lyr = ds.GetLayerByName( "dist_google" ) > > lyr.ResetReading() > > feat = lyr.GetNextFeature() > while feat is not None: > print str(feat.GetFieldAsInteger("COLOR")), # shows 0 > feat.SetField(13,-1) > print "changed to: "+ str(feat.GetFieldAsInteger("COLOR")) # > shows -1 > feat = lyr.GetNextFeature() > > ds.Destroy() > > > ds = ogr.Open( "dist_google.shp", 1 ) > lyr = ds.GetLayerByName( "dist_google" ) > feat = lyr.GetNextFeature() > while feat is not None: > print str(feat.GetFieldAsInteger("COLOR")), # shows 0 !!!! > feat = lyr.GetNextFeature()
