Readogr() Cannot Open File

readOGR() cannot open file

You could have shown that you have the right path with:

list.files('~/R/funwithR/data/ne_110m_land', pattern='\\.shp$')
file.exists('~/R/funwithR/data/ne_110m_land/ne_110m_land.shp')

perhaps try:

readOGR(dsn=path.expand("~/R/funwithR/data/ne_110m_land"), layer="ne_110m_land")

or a simpler alternative that is wrapped around that:

library(raster)
s <- shapefile("~/R/funwithR/data/ne_110m_land/ne_110m_land.shp")

Update:

rgdal has changed a bit and you do not need to separate the path and layer anymore (at least for some formats). So you can do

x <- readOGR("~/R/funwithR/data/ne_110m_land/ne_110m_land.shp")

(perhaps still using path.expand)

Also, if you are still using readOGR you are a bit behind the times. It is better to use terra::vect or sf::st_read.

R: readOGR() cannot open file

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.

readOGR(), cannot open file error

Check inside the Shapefile folder if the .shp, .dbf, .xml, .shx, and .prj files are actually named as Shapefile. I did that and it helped . I hope it helps you too

readOGR cannot open layer error

Try altering the layer name to the filename without the extension:

countries <- readOGR("https://raw.githubusercontent.com/datasets/geoboundaries-world-110m/master/countries.geojson", layer = "countries")

For some reason in some environments the layer needs to be called "OGRGeoJSON", in other it needs to be called the filename without the extension.

For example with the latest R and rgdal versions on my OSX, it requires "OGRGeoJSON", but on our production machine running CentOS, it requires the filename. I suspect this is something to do with different versions of the underlying gdal C libraries.

R: readOGR() cannot open file

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.



Related Topics



Leave a reply



Submit