[GIS] R will not read shapefile / file.exists returns true

errorrshapefile

I cannot successfully read a shapefile in R.

I'm using Rstudio version 0.99.902

I have read several articles on readOGR errors that concern reading a shapefile.

My shapefile is error free, as it opens in qGIS. when I check prescence of file, file.exists returns TRUE yet I get a "Cannot open layer" error:

Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = >>use_iconv, : Cannot open layer

Any advice?

Best Answer

It took me a bit to get this too.

# shapefile path example:
# C:/Users/User/GIS/MyShapefile.shp

# OGR command:
library(rgdal)
readOGR("C:/Users/User/GIS", "MyShapefile")

You have to leave off the ".shp" extension as well as the last forward slash on the path.

Related Question