I downloaded a SHAPE file from here. I added to my working directory:
> list.files('/home/lucho/data/EnglandGIS/', pattern='\\.shp$')
[1] "england_gor_2011.shp"
> file.exists('/home/lucho/data/EnglandGIS/england_gor_2011.shp')
[1] TRUE
However, I cannot read it:
library("rgdal")
shape <- readOGR(dsn = path.expand("/home/lucho/data/EnglandGIS/england_gor_2011"), layer = "england_gor_2011")
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :
Cannot open file
The only other similar question with accepted answer is of not help. What is the problem? Is the data corrupted? How can I tell? (if you could download the data and try it yourself, that might be the best way)
I am using latest R with latest Rstudio, in Ubuntu 16.04.
To import shape files with readOGR
you can either use
readOGR(dsn = "/home/lucho/data/EnglandGIS/", layer = "england_gor_2011")
where dsn
is the folder containing england_gor_2011.shp
(and other files with the same name but different extensions, e.g. england_gor_2011.dbf
, etc.) or you can specify the full path to the shape file (including the extension):
readOGR("/home/lucho/data/EnglandGIS/england_gor_2011.shp")
The second method won't work for earlier versions of rgdal
as far as I remember.