I'm modifying the Arrows plugin by Gregoire Piffault. It writes the output to a shapefile, but if the shapefile already exists it fails. He tries to remove the file using QgsMapLayerRegistry.instance().removeMapLayer then write a new one using QgsVectorFileWriter, which results in an empty file; if the file doesn't already exist it works fine.
I've tried simply deleting the file using os.remove after the call to removeMapLayer, but the file is still locked.
os.remove(self.conf["arrow_outshape"]) WindowsError: [Error 32] The process cannot access the file because it is being used by another process: u'C:/GIS/SK/Saskatoon/mpArrows.shp I think there are two options:
- change the code substantially to allow for editing the existing file rather than creating a new one if it already is loaded
- figure out how to completely unload the file after removing the map layer so that I can delete it