2

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

2

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.