Skip to content
Prev 15069 / 29559 Next

Problem with writeOGR and overwrite_layer=T

On Mon, 14 May 2012, Bastien.Ferland-Raymond at mrnf.gouv.qc.ca wrote:

            
I can reproduce the problem on Windows 7 with GDAL 1.9.0, that is, that 
parts of shapefiles created by OGR (the *.dbf and *.shp files) cannot be 
deleted by poDS->DeleteLayer() - line 473 in rgdal/src/ogrsource.cpp. This 
also applies before trying to overwrite them - they cannot be deleted in 
Windows Explorer either until the R session exits. Running as 
administrator does not help either.

This appears to be an interaction between Windows (7 in my case), GDAL >= 
1.8.0, which introduced bans on overwriting for Shapefiles, and possibly 
some unknown factors.

This is not a problem I can resolve, certainly not any time soon. It is 
not an R code problem as such (I believe), and the stackoverflow 
speculation is misleading, this has nothing to do with connections, only 
with Windows apparent file usage status.

I would appeal to interested Windows users to contribute a solution - you 
will need to be able to cross-compile GDAL for Windows under MSYS, and to 
build R packages. If Windows users know how to unlink files with an 
incorrect usage status without exiting R, this would possibly help, but 
doesn't get us much further.

Other GDAL/OGR uses such as ogr2ogr exit on error, but it might be helpful 
to know if ogr2ogr does the same - that is, is unable to overwrite a 
layer. MapInfo File, GML and other drivers do not seem to suffer from the 
same issue. Again, checking across a wider range of drivers would help.

Roger