如何在R中过滤大型geojson文件
我在用R过滤一个大的geojson文件时遇到问题。如果我只想显示一个国家的地图,我不想加载整个欧洲地图,因为这是巨大的。所以我想过滤这个数据集,比如保加利亚--如何在R中过滤大型geojson文件,r,json,geojson,r-highcharter,R,Json,Geojson,R Highcharter,我在用R过滤一个大的geojson文件时遇到问题。如果我只想显示一个国家的地图,我不想加载整个欧洲地图,因为这是巨大的。所以我想过滤这个数据集,比如保加利亚--CNTR_code==“BG”,但我无法管理。 请在下面找到要下载的代码,以及没有达到预期效果的初始努力 link <- 'https://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/download/ref-nuts-2013-01m.geojson.zip' te
CNTR_code==“BG”
,但我无法管理。
请在下面找到要下载的代码,以及没有达到预期效果的初始努力
link <- 'https://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/download/ref-nuts-2013-01m.geojson.zip'
temp <- tempfile()
download.file(link,temp)
mapdata <- readLines(unzip(temp, "NUTS_RG_01M_2013_4326_LEVL_3.geojson"))
mapdata <- jsonlite::fromJSON(mapdata, simplifyVector = FALSE)
#glimpse(mapdata)
mapdata$features[[100]]$properties$CNTR_CODE
[1] "BG"
library(sf)
mapdata2 <- copy(mapdata)
mapdata2 %>%
filter(CNTR_CODE %in% c('BG'))
link如果您想要一个列表,那么Filter
可以工作:
path = "NUTS_RG_01M_2013_4326_LEVL_3.geojson"
x <- jsonlite::fromJSON(path, simplifyVector = FALSE)
x$features <- Filter(function(z) z$properties$CNTR_CODE == "BG", x$features)
vapply(x$features, function(x) x$properties$CNTR_CODE, "")
path=“NUTS\u RG\u 01M\u 2013\u 4326\u level\u 3.geojson”
x如果您想要一个列表,那么Filter
可以工作:
path = "NUTS_RG_01M_2013_4326_LEVL_3.geojson"
x <- jsonlite::fromJSON(path, simplifyVector = FALSE)
x$features <- Filter(function(z) z$properties$CNTR_CODE == "BG", x$features)
vapply(x$features, function(x) x$properties$CNTR_CODE, "")
path=“NUTS\u RG\u 01M\u 2013\u 4326\u level\u 3.geojson”
如果使用正确的工具,那么这个文件就不会那么大
library(geojsonsf)
可以将geojson直接读取到sf
对象
库(mapdeck)
可以绘制所有多边形
或是整个地块
mapdeck(
style = mapdeck_style("dark")
) %>%
add_polygon(
data = sf
, fill_colour = "NUTS_NAME"
, legend = T
)
如果使用正确的工具,那么这个文件就不会那么大
library(geojsonsf)
可以将geojson直接读取到sf
对象
库(mapdeck)
可以绘制所有多边形
或是整个地块
mapdeck(
style = mapdeck_style("dark")
) %>%
add_polygon(
data = sf
, fill_colour = "NUTS_NAME"
, legend = T
)
mapdeck(
style = mapdeck_style("dark")
) %>%
add_polygon(
data = sf
, fill_colour = "NUTS_NAME"
, legend = T
)