我想使用jsonlite和leaflet来可视化R中的一些多多边形。这是我的初始代码:
library(leaflet)
library(jsonlite)
library(geojsonlint)
url <- paste0("https://geodata.nationaalgeoregister.nl/cbsgebiedsindelingen/wfs?",
"request=GetFeature&service=WFS&version=1.1.0&",
"typeName=cbsgebiedsindelingen:cbs_arrondissementsgebied_2019_gegeneraliseerd&",
"outputFormat=application/json&srsName=EPSG:4326&propertyName=geom,statcode")
boundaries <- jsonlite::fromJSON(url)
geojson_validate(x = as.location(url))
leaflet() %>%
addTiles() %>%
addGeoJSON(boundaries) %>%
setView(5.387740, 52.155499, 7)GeoJSON文件有效。但是,多重多边形不会显示在地图上。
当我使用readr修改我的代码时,它们被显示出来,一切看起来都很好:
library(readr)
leaflet() %>%
addTiles() %>%
addGeoJSON(read_lines(url) %>% paste(collapse = "\n")) %>%
setView(5.387740, 52.155499, 7)我想要将另一个数据集中的列添加到多多边形的特征数据中,以便创建一个脉动图。所以我真的希望第一个代码块能够工作。
当我使用jsonlite读取GeoJSON文件时,为什么不显示多多边形?
发布于 2020-04-29 23:54:40
在第一个代码块中,GeoJSON文件中的features数组被解析为长度为11的列表。在第二个代码块中,解析为11列的数据帧。解决方案似乎是:
boundaries <- jsonlite::fromJSON(url, simplifyVector = FALSE)https://stackoverflow.com/questions/61505190
复制相似问题