. Advertisement .
..3..
. Advertisement .
..4..
I get the error: error in ogrlistlayers(dsn = dsn) : cannot open data source when I try to run the program below:
wmap <- readOGR(dsn="~/R/funwithR/data/ne_110m_land", layer="ne_110m_land")
ne_110m_land.dbf
ne_110m_land.prj
ne_110m_land.shp
ne_110m_land.shx
ne_110m_land.VERSION.txt
ne_110m_land.README.html
The error appears the system notifies as follows:
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :
Cannot open file
I tried to solve it with another sample. I got the reference in the community forum, but it still returned an invalid result. If someone knows the solution, please give me the support. Thanks!
The cause: Because
readOGR
does not usepath.expand
, it does not function. As it is unsure if the first input is indeed a file path (It might represent a database).Solution: To fix the error in ogrlistlayers(dsn = dsn) : cannot open data source, I recommend 3 ways to change your code:
The command returned an error
Cannot open layer
for me when I added thedsn
orlayer
tags.It worked when I added it all as
readOGR('~/R/funwithR/data/ne_110m_land/ne_110m_land.shp')
.Please note that my file was a GJSON, so I have only seen it with
readOGR('~/R/funwithR/data/ne_110m_land/ne_110m_land.gjson')