BLUF:您需要的不仅仅是.shp
个文件.解压缩更多(所有)的文件,您会得到不同的结果.
对于下面的每个文件,我在命令行上使用unzip
来仅解压缩该步骤中的文件.在此期间,我删除未测试的文件.我不相信在R到unz(..)
中有一种方法可以到达所有的文件.
只有94e2701.shp
:错误
.shp
和.prj
:错误
.shp
和.dbf
文件:错误
.shp
和.shx
:部分成功,不填充CRS
data <- sf::st_read("94e2701.shp")
# Reading layer `94e2701' from data source `C:\Users\r2\AppData\Local\Temp\Rtmpqoj4GE\94e2701.shp' using driver `ESRI Shapefile'
# Simple feature collection with 2 features and 0 fields
# Geometry type: POLYGON
# Dimension: XY
# Bounding box: xmin: -100.4 ymin: 28.27 xmax: -91.4 ymax: 39.77
# CRS: NA
.shp
、.shx
和.dbf
:与4相同,编号CRS
.shp
、.shx
、.dbf
和.prj
:104
data <- sf::st_read("94e2701.shp")
# Reading layer `94e2701' from data source `C:\Users\r2\AppData\Local\Temp\Rtmpqoj4GE\94e2701.shp' using driver `ESRI Shapefile'
# Simple feature collection with 2 features and 7 fields
# Geometry type: POLYGON
# Dimension: XY
# Bounding box: xmin: -100.4 ymin: 28.27 xmax: -91.4 ymax: 39.77
# Geodetic CRS: GCS_Sphere_EMEP
顺便说一句,让我判断这一点的是每?sf::st_read
段中就有一段:
请注意,数据源目录(如*.dbf
)中的零散文件可能会导致伴随‘*.shp’丢失的虚假错误.
这让我想知道目录中是否存在其他文件导致了您的问题.
我不相信有一种方法在R到unz(..)
,以达到所有的文件.如果您不想将它们解压缩到当前目录中(只需"查看"这些文件,然后将其丢弃),那么您可以创建一个temp directory,将其解压缩到其中,然后从那里打开文件.
dir.create(td <- tempfile())
unzip(tmp, exdir = td)
data <- sf::st_read(file.path(td, f_name))
# Reading layer `94e2701' from data source `C:\Users\r2\AppData\Local\Temp\Rtmpqoj4GE\file185581a1d4d01\94e2701.shp' using driver `ESRI Shapefile'
# Simple feature collection with 2 features and 7 fields
# Geometry type: POLYGON
# Dimension: XY
# Bounding box: xmin: -100.4 ymin: 28.27 xmax: -91.4 ymax: 39.77
# Geodetic CRS: GCS_Sphere_EMEP