I have a small Python script which is supposed to delete a shapefile in case the file is empty.
import sys
from osgeo import ogr
drv = ogr.GetDriverByName("ESRI Shapefile")
ds = drv.Open(inData)
if ds is None:
print "Could not open file."
sys.exit(1)
lyr = ds.GetLayer()
if lyr.GetFeatureCount() == 0:
drv.DeleteDataSource(inData)
everything seems to work fine. The shapefile consists of
- shapefile.dbf
- shapefile.prj
- shapefile.shp
- shapefile.shx
whereas only the *.prj and *.shx get deleted. the *.dbf and *.shp are untouched. Is there anything I am missing?
asked Jul 16, 2014 at 10:57
1 Answer 1
found the problem:
the files were still busy from the check if it contains geometries.
ds=None
lyr=None
Setting both variables = None before actually deleting the file solves the problem.
answered Jul 17, 2014 at 8:13
default