首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RStudio,读取shapefiles的Rstudio.cloud错误

RStudio,读取shapefiles的Rstudio.cloud错误
EN

Stack Overflow用户
提问于 2022-01-30 23:13:23
回答 1查看 250关注 0票数 0

我已经加载了多个包/尝试过许多读取.shp的方法。所有的方法都不起作用,我无法破解谷歌相关的建议。运行R中的代码,系统冻结,RStudio.cloud中相同的代码只返回各种错误消息。包和代码的列表如下。最终,我试图创建映射,加入另一个文件并生成一个结果表。如有任何建议,将不胜感激。

代码语言:javascript
复制
library(rgeos)
library(sp)
library(rgdal)
library(maptools)
library(sf)

require(sf)
area <- read_sf(dsn = ".", layer = "2020ATLclip")

require(rgdal)
shape <- readOGR(dsn= ".", layer = "2020ATLclip.shp")

shape <- readOGR(dsn= ".", layer = "tl_2021_13_concity.shp")

library(raster)

l = readShapePoly("2020ATLclip.shp")
l = readShapePoly("tl_2021_13_concity.shp")

atl.poly <- readOGR("./data", layer = "tl_2021-13_concity.shp")


Cannot open layer 2020ATLclip
Error in CPL_read_ogr(dsn, layer, query, as.character(options), quiet,  : 
  Opening layer failed.
In addition: Warning messages:
1: Unable to open /cloud/project/2020ATLclip.shx or /cloud/project/2020ATLclip.SHX. Set SHAPE_RESTORE_SHX config option to YES to restore or create it. (GDAL error 4) 
2: Failed to open file /cloud/project/2020ATLclip.shp.  It may be corrupt or read-only file accessed in update mode. (GDAL error 4) 
>

Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  : 
  Cannot open layer


 l = readShapePoly("2020ATLclip.shp")
Error in getinfo.shape(filen) : Error opening SHP file
In addition: Warning message:
readShapePoly is deprecated; use rgdal::readOGR or sf::st_read 

> l = readShapePoly("tl_2021_13_concity.shp")
Error in getinfo.shape(filen) : Error opening SHP file
In addition: Warning message:
readShapePoly is deprecated; use rgdal::readOGR or sf::st_read
EN

回答 1

Stack Overflow用户

发布于 2022-01-31 12:00:09

对于readOGR (来自rgdal包)和st_read (来自较新的sf包),当导入shapefile时,dsn=参数必须指向带有扩展名*.shp的shp文件。对于shapefile来说,layer=参数是不必要的。您的还必须在相同的目录中具有shapefile格式的其他组件:*.shx、*.dbf和*.prj。假设你在当前的工作目录中有这些文件,那么.

如果您坚持使用rgdal库:

代码语言:javascript
复制
library(rgdal)
shape <- readOGR(dsn= "2020ATLclip.shp")
# returns an object of class Spatial*DataFrame from sp

最好你换到sf,然后

代码语言:javascript
复制
library(sf)
shape <- st_read(dsn = "2020ATLclip.shp")
# returns an object of class sf
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70919780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档