I am trying to plot a shapefile on top of a raster using the command readOGR
. My current code is:
CEZ <- readOGR(".", "Shapefile/CEZ1")
This is followed by the error code
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, : Cannot open data source
I am unsure what this code means - Is it a problem with the shapefile, the command or the way I have structured the path?
dsn
is the path and thelayer
argument is the name of the shapefile without the .shp extension. You are passing a partial path argument to the layer argument where it should just be "CEZ1". If you need to get to a sub-directory in your wd you can use something likefile.path(getwd(), "Shapefile")
for the dsn argument. The suggestion by @Spacedman removes these complications.