无法将 geojson 数据读入 R

Trouble reading geojson data into R

我正在尝试读取 geojson 数据以与 leaflet 包一起使用。我试过以多种方式读取数据,但我无法绘制它。数据为here.

这是你想要的吗?

library(leaflet)
library(jsonlite)
download.file("https://opendata.arcgis.com/datasets/772f3621fa354ec9abf3ba33f3ace59e_0.geojson", "RPD_Sections.geojson")
x = fromJSON("RPD_Sections.geojson", FALSE)
leaflet() %>% addTiles() %>% addGeoJSON(x) %>% setView(
    lng = mean(vapply(x$features[[1]]$geometry$coordinates[[1]], "[[", 1, 1)),
    lat = mean(vapply(x$features[[1]]$geometry$coordinates[[1]], "[[", 1, 2)),
    zoom = 12)

更简洁一点,但给出相同的结果

library(sf)
library(leaflet)
sf <- sf::st_read("https://opendata.arcgis.com/datasets/772f3621fa354ec9abf3ba33f3ace59e_0.geojson")

leaflet() %>%
  addTiles() %>%
  addPolygons(data = sf)

这也假设您的 GeoJSON 仅由多边形组成