如何使用 r 中的 sf 包从 .shapefile 读取和绘图?

How to read & plot from .shp files using sf package in r?

我是 geospatial 数据的新手,尝试使用 .shp 文件进行绘图但出现错误。

这个.shp文件中的几何类型LINESTRING,似乎与MULTIPOLYGON不同这是我在使用 sf

之前绘制的

形状文件来源: 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

预期结果:

代码尝试:

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
ind_global %>% 
  st_as_sf() %>% 
  ggplot() +
  geom_sf()

Error in st_cast.POINT(X[[i]], ...) : cannot create MULTILINESTRING from POINT

我是否需要以其他方式处理 LINESTRING 几何 .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()