wmap <- readOGR(dsn="~/R/funwithR/data/ne_110m_land", layer="ne_110m_land")
此代码未加载形状文件,错误生成为
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :
Cannot open file
我确信该目录是正确的。最后/也不存在,图层名称也正确。
我所拥有的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
答案 0 :(得分:50)
你可能已经证明你有正确的道路:
list.files('~/R/funwithR/data/ne_110m_land', pattern='\\.shp$')
file.exists('~/R/funwithR/data/ne_110m_land/ne_110m_land.shp')
也许试试:
readOGR(dsn=path.expand("~/R/funwithR/data/ne_110m_land"), layer="ne_110m_land")
或更简单的替代方案:
library(raster)
s <- shapefile("~/R/funwithR/data/ne_110m_land/ne_110m_land.shp")
答案 1 :(得分:2)
对我来说,当我添加Cannot open layer
和dsn
代码时,该命令会返回layer
错误。
所以当我把它全部包括在内的时候
readOGR('~/R/funwithR/data/ne_110m_land/ne_110m_land.shp')
它奏效了。
请注意,我的文件是gjson,所以我只看到了这个
readOGR('~/R/funwithR/data/ne_110m_land/ne_110m_land.gjson')
答案 2 :(得分:1)
我有同样的错误。要读取shapefile,您的文件夹中需要包含三个文件:.shp,.dbf和.shx文件。
答案 3 :(得分:0)
这是对我有用的(有一个真实的例子)
require(rgdal)
shape <- readOGR(dsn = "1259030001_ste11aaust_shape/STE11aAust.shp", layer = "STE11aAust")
确切的数据可用here(下载名为“州和领地ASGC Ed 2011数字边界,采用MapInfo互换格式”的.zip文件)
答案 4 :(得分:0)
正如我在其他文章(Error when opening shapefile)中所述,使用file.choose()并手动选择将在需要选择一个文件的情况下提供帮助。显然与NaturalEarth shapefile有关
答案 5 :(得分:0)
语法:library(raster)
s <- shapefile("~/R/funwithR/data/ne_110m_land/ne_110m_land.shp")
运作良好!托达拉卜!
答案 6 :(得分:0)
在我看来,这是解决方案,至少在将其上传到云之前
######################################
# Server
######################################
#I tell R where to extract the data from
#Le digo al R donde debe jalar la data
dirmapas <- "E:/Tu-carpeta/Tu-sub-carpeta/ESRI" #Depende donde tengas tú tus
#archivos de cartografía
setwd(dirmapas)
#The raw map
# El mapa de polígonos en blanco y negro
departamentos<-readOGR(dsn="BAS_LIM_DEPARTAMENTO.shp", layer="BAS_LIM_DEPARTAMENTO")