如何解决如何在 r 中使用 sf 包从 .shp 文件读取和绘图?
我不熟悉 geospatial
数据并尝试使用 .shp
文件进行绘图但出现错误。
.shp 文件中的 几何类型 是 LInesTRING
,它似乎与我在使用 {{ 之前绘制的 MULTIpolyGON
不同1}}
形状文件来源: https://github.com/johnsnow09/covid19-df_stack-code/blob/main/in_country_boundaries.shp
shapefile 的原始来源: https://github.com/wri/wri-bounds/blob/master/dist/in_countries.zip
预期结果:
代码尝试:
sf
library(tidyverse)
library(sf)
ind_global <- sf::read_sf("path/in_country_boundaries.shp")
ind_global
Simple feature collection with 412 features and 9 fields
Geometry type: LInesTRING
Dimension: XY
Bounding Box: xmin: -141.0056 ymin: -54.88624 xmax: 140.9776 ymax: 70.07531
Geodetic CRS: WGS 84
st_cast.POINT(X[[i]],...) 中的错误:无法创建 MULTILInesTRING 从点
我是否需要以其他方式处理 ind_global %>%
st_as_sf() %>%
ggplot() +
geom_sf()
geometry .shp 文件?
解决方法
删除 st_as_sf() %>%
后代码运行良好。我已经从 https://github.com/wri/wri-bounds/blob/master/dist/in_countries.zip 下载了 shapefile,它只是 MULTIPOLYGON。
library(tidyverse)
library(sf)
ind_global <- sf::read_sf("...\\in_countries.shp")
ind_global
ind_global %>%
ggplot() +
geom_sf()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。