Hello all,

I'm trying to delete a number of records from shapefile based on an
attribute. The strange thing that is happening is that feature count never
changes but if i make the same filter a second time the features are no
longer there. The code i'm using is below. I should be doing something
wrong for sure.

import os
from osgeo import ogr

path = 'C:\\datasets'
os.chdir(path)

shp = ogr.Open('locais.shp',1)

layer = shp.GetLayer(0)
print layer.GetFeatureCount()
layer.SetAttributeFilter('name ilike "nacional%"')

feat = layer.GetNextFeature()
while feat:
    featId = feat.GetFID()
    layer.DeleteFeature(featId)
    feat = layer.GetNextFeature()

shp.Destroy()

Any suggestions? Thanks in advance.
Regards,

-- 
Hugo Martins
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to