2

I tried using rgdal::writeOGR in R to overwrite a SHP file that was open in QGIS.

Error in writeOGR(x, "C:/myFiles", "testFile", : 
   Creation of output file failed

Not only did it fail to overwrite the file, but it also deleted all the following auxiliary files:

testFile.cpg
testFile.prj
testFile.shx
testFile.sbx

Basically everything except the dbf and shp files. This seems to be standard behavior, and happens every time that I have a file open in QGIS. This also happens whether or not the file is being edited in QGIS.

I'm aware that it's possible to regenerate some of these to save the file, but I'd prefer to avoid this problem altogether by catching a QGIS file lock.

Is there any way (in Python, R or any other) to detect that QGIS has locked a file BEFORE trying to overwrite it? My operating system is Windows 10.

  • What operating system? Is this reproducible, or did it happen once? What are the steps that did this? Was the file opened for editing in QGIS? (also, SHXs can be regenerated from the SHP so its not fatal on the Shapefile). – Spacedman Jan 16 at 20:03
  • Thanks for the tip regarding regenerating SHX files. I'll update the original question with more details – Andrew Plowright Jan 17 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.