我已经加载了多个包/尝试过许多读取.shp的方法。所有的方法都不起作用,我无法破解谷歌相关的建议。运行R中的代码,系统冻结,RStudio.cloud中相同的代码只返回各种错误消息。包和代码的列表如下。最终,我试图创建映射,加入另一个文件并生成一个结果表。如有任何建议,将不胜感激。
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发布于 2022-01-31 12:00:09
对于readOGR (来自rgdal包)和st_read (来自较新的sf包),当导入shapefile时,dsn=参数必须指向带有扩展名*.shp的shp文件。对于shapefile来说,layer=参数是不必要的。您的还必须在相同的目录中具有shapefile格式的其他组件:*.shx、*.dbf和*.prj。假设你在当前的工作目录中有这些文件,那么.
如果您坚持使用rgdal库:
library(rgdal)
shape <- readOGR(dsn= "2020ATLclip.shp")
# returns an object of class Spatial*DataFrame from sp最好你换到sf,然后
library(sf)
shape <- st_read(dsn = "2020ATLclip.shp")
# returns an object of class sfhttps://stackoverflow.com/questions/70919780
复制相似问题