Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, : Cannot open fileI am sure that the directory is correct one. At the end / is also not there and layer name is also correct.

You are watching: Error in ogrlistlayers(dsn = dsn) : cannot open data source

Inside the ne_110m_land directory files I have are:

ne_110m_land.dbfne_110m_land.prjne_110m_land.shpne_110m_land.shxne_110m_land.VERSION.txtne_110m_land.README.html

*

*

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 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 (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.


Share
Improve this answer
Follow
edited Jul 2 at 14:50
answered May 31 "15 at 19:53
*

Robert HijmansRobert Hijmans
26k33 gold badges3737 silver badges4444 bronze badges
5
Add a comment |
8
For me, the command returned the Cannot open layer error when I included the dsn and layer tags.

So when I included it all just as readOGR("~/R/funwithR/data/ne_110m_land/ne_110m_land.shp")it worked.

Note that my file was a gjson, so I"ve only seen this withreadOGR("~/R/funwithR/data/ne_110m_land/ne_110m_land.gjson")


Share
Improve this answer
Follow
answered Jun 7 "18 at 1:37
*

Tom LoganTom Logan
31133 silver badges1212 bronze badges
Add a comment |
7
I had the same error. To read in a shapefile, you need to have three files in your folder: the .shp, .dbf and .shx files.


Share
Improve this answer
Follow
answered Oct 24 "19 at 8:12
*

E. VrE. Vr
7111 silver badge11 bronze badge
0
Add a comment |
1
Here"s what worked for me (with a real example)

require(rgdal)shape The exact data is available here (download the .zip file called "State and Territory ASGC Ed 2011 Digital Boundaries in MapInfo Interchange Format")


Share
Improve this answer
Follow
answered Feb 24 "19 at 4:55
stevecstevec
18.6k77 gold badges8383 silver badges126126 bronze badges
Add a comment |
1
the syntax: library(raster)s worked perfectly! todah rabah!


Share
Improve this answer
Follow
edited Aug 6 "20 at 13:55
con
4,53555 gold badges2020 silver badges4545 bronze badges
answered Aug 6 "20 at 12:45
Álon AlheviÁlon Alhevi
1111 bronze badge
Add a comment |
0
As I commented in other post (Error when opening shapefile), using file.choose() and selecting manually will help in the case one file selection is needed. Apparently is related with NaturalEarth shapefiles


Share
Improve this answer
Follow
answered May 31 "19 at 15:53
Kita Romero-ÁlvarezKita Romero-Álvarez
1111 bronze badge
Add a comment |
0
it seems to me that this is the solution, at least before uploading it to the cloud

###################################### # Server ###################################### #I tell R where to extract the data from #Le digo al R donde debe jalar la data dirmapas
Share
Improve this answer
Follow
answered Dec 8 "20 at 17:06
Gustavo EspinozaGustavo Espinoza
111 bronze badge
Add a comment |
0
the Mandatory files should be all in the same directory

.shp — shape format

.shx — shape index format;

.dbf — attribute format;

then we can just give the path as a parameter to the function it will work.

global_24h =readOGR( "/Users/m-store/Desktop/R_Programing/global_24h.shp")


Share
Improve this answer
Follow
answered 2 days ago
Daham MustafaDaham Mustafa
111 bronze badge
1
Add a comment |

Your Answer


Thanks for contributing an answer to Stack Overflow!

Please be sure to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

See more: Does Maui Moisture Cause Hair Loss, According To A Dermatologist


Draft saved
Draft discarded

Sign up or log in


Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Submit

Post as a guest


Name
Email Required, but never shown


Post as a guest


Name
Email

Required, but never shown


Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy


Not the answer you're looking for? Browse other questions tagged r gdal rgdal ogr or ask your own question.


The Overflow Blog
Featured on Meta
Linked
4
Error when opening shapefile
-1
R: readOGR() cannot open file
0
Cannot open shp file
1
Cannot open OGR file
Related
825
data.table vs dplyr: can one do something well the other can't or does poorly?
4
Are DWG files supported by readOGR in the rgdal package?
0
How can I open an unzipped map file
4
readOGR(), "cannot open file" error
2
Reading a DXF file in R with readOGR
1
R rgdal::readOGR issue with file path refering to linux home directory
Hot Network Questions more hot questions

Question feed
Subscribe to RSS
Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader.


lang-r
Stack Overflow
Products
Company
Stack Exchange Network
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.9.14.40215


Stack Overflow works best with JavaScript enabled
*

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.