r - shp的R函数
问题描述
我正在尝试在 R 中读取我的 shapefile,但仍然收到错误消息
我安装了这些库
library(sf)
library(ggplot2)
library(tmap)
library(tmaptools)
library(leaflet)
library(dplyr)
mydata<-st_read("C:/Users/User/Documents/PlotLocations_HARV.shp",stringsAsFactors = FALSE)
我收到此错误消息:
Cannot open data source C:\Users\User\Documents\PlotLocations_HARV.shp
Error in CPL_read_ogr(dsn, layer, as.character(options), quiet, type, :
Open failed.
In addition: Warning message:
In CPL_read_ogr(dsn, layer, as.character(options), quiet, type, :
GDAL Error 4: Unable to open C:\Users\User\Documents\PlotLocations_HARV.shx or C:\Users\User\Documents\PlotLocations_HARV.SHX.Try --config SHAPE_RESTORE_SHX true to restore or create it
我也有整个文件
aoi_boundary_HARV <- st_read("C:\Users\rhusein\Documents\NEONDSSiteLayoutFiles\NEON-DS-Site-Layout-Files\HARV\HarClip_UTMZ18.shp")
并且仍然收到错误消息
CPL_read_ogr (dsn, layer, as.character(options), quiet, type, 中的错误:打开失败。 – julia 1 小时前
验证文件 PlotLocations_HARV.shx 是否存在于与 PlotLocations_HARV.shp 相同的文件夹中
是的,两者都在文件夹中
现在我很好,谢谢
解决方案
“shapefile”由多个具有不同扩展名的文件组成。
- .shp - 此文件包含特征的几何图形。
- .shx -- 空间索引
- .dbf -- 属性值
除非这些文件都在那里,否则该文件将不会打开。ESRI 将其称为形状文件有点误导,但你有它。
您将看到其他几个,例如用于空间参考的.prj和用于元数据的.xml,但它们不是必需的。
你的错误是
Unable to open C:\Users\User\Documents\PlotLocations_HARV.shx
这意味着您由于某种原因无法打开空间索引文件。
所以解决问题,你可以确保*.shx文件和.shp文件在同一个文件夹中,或者使用选项SHAPE_RESTORE_SHX
重新生成索引。
您说“现在我很好”,所以我假设您找到了文件并将其移到那里,或者重新生成了索引。
推荐阅读
- vuejs2 - 如何在 vue 组件中使用 videojs 热键插件?
- html - 如何使用 CSS 在下拉菜单上放置动画?
- php - 为什么当我尝试在 Slim3 中使用 PDO::PARAM_STR 时,Slim 会返回错误?
- powershell - $($args[2]) 没有打印参数传递
- amazon-web-services - 我有一个在 ec2 上运行的服务器,但我无法连接到 localhost 8085。有什么建议吗?
- amazon-web-services - 使用 Kinesis Analytics 解析复杂的 JSON
- email - 如何在 spf 记录中允许 Yahoo.com?
- android - cardView android studio上的厚左边框
- python - 矢量化查找另一行 + 计算字段
- c# - 如何获得达到关键和重新订购级别的通知