readOGR() cannot open file

后端 未结 6 918
臣服心动
臣服心动 2020-12-08 00:50
wmap <- readOGR(dsn=\"~/R/funwithR/data/ne_110m_land\", layer=\"ne_110m_land\")

This code is not loading the shape file and error is generated a

相关标签:
6条回答
  • 2020-12-08 01:21

    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 with readOGR('~/R/funwithR/data/ne_110m_land/ne_110m_land.gjson')

    0 讨论(0)
  • 2020-12-08 01:21

    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.

    0 讨论(0)
  • 2020-12-08 01:24

    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

    0 讨论(0)
  • 2020-12-08 01:30

    Here's what worked for me (with a real example)

    require(rgdal)
    shape <- readOGR(dsn = "1259030001_ste11aaust_shape/STE11aAust.shp", layer = "STE11aAust")
    

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

    0 讨论(0)
  • 2020-12-08 01:30

    the syntax: library(raster) s <- shapefile("~/R/funwithR/data/ne_110m_land/ne_110m_land.shp") worked perfectly! todah rabah!

    0 讨论(0)
  • 2020-12-08 01:37

    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")
    
    0 讨论(0)
提交回复
热议问题