R - 删除形状文件中的领土并聚合到更高的 NUTS 级别
R - Remove Territories in shape file and aggregate to higher NUTS level
我正在尝试创建欧盟 shapefile。我想删除所有海外领土,然后绘制国家边界。我使用“NUTS_RG_01M_2021_3035_LEVL_1.shp”从 Eurostat (http://gisco-services.ec.europa.eu/distribution/v2/countries/download/ref-countries-2020-01m.shp.zip) 下载了 NUTS1 Level Shapefile,并删除了海外领土(西班牙、法国、葡萄牙等)。现在我基本上想聚合回 NUTS0 级别,只绘制外部国家边界。这可能吗?我试过 st_union 但这会聚集到欧盟外部边界,删除所有边界。
目前我的代码如下:
#read shapefile
EU.sf <- st_read("/ref-nuts-2021-01m.shp/NUTS_RG_01M_2021_3035_LEVL_1.shp/NUTS_RG_01M_2021_3035_LEVL_1.shp")
#plot without oversea territories
EUmap <- tm_shape(st_union(subset(EU.sf,
NUTS_ID != "FRY" &
NUTS_ID != "PT2" &
NUTS_ID != "PT3" &
NUTS_ID != "ES7" &
CNTR_CODE != "TR"
))) +
tm_borders()
谢谢!
我不太清楚您的预期结果,但看起来 NUTS1 文件中的 CNTR_CODE
变量包含与 NUTS0 边界等效的国家/地区代码。如果是这种情况,您可以使用 dplyr::count()
组合 NUTS1 文件中具有相同 CNTR_CODE
的所有多边形。
请注意,在此示例中,我从此处下载了边界的 geojson:https://gisco-services.ec.europa.eu/distribution/v1/nuts-2021.html
library(sf)
library(tidyverse)
tmp <- tempfile()
download.file("https://gisco-services.ec.europa.eu/distribution/v2/nuts/geojson/NUTS_RG_01M_2021_3035_LEVL_1.geojson", tmp)
nuts1 <- read_sf(tmp)
nuts_agg <- nuts1 %>%
filter(!NUTS_ID %in% c("FRY", "PT2", "PT3", "ES7") & CNTR_CODE != "TR") %>%
count(CNTR_CODE)
nuts_agg %>%
ggplot() +
geom_sf()
我正在尝试创建欧盟 shapefile。我想删除所有海外领土,然后绘制国家边界。我使用“NUTS_RG_01M_2021_3035_LEVL_1.shp”从 Eurostat (http://gisco-services.ec.europa.eu/distribution/v2/countries/download/ref-countries-2020-01m.shp.zip) 下载了 NUTS1 Level Shapefile,并删除了海外领土(西班牙、法国、葡萄牙等)。现在我基本上想聚合回 NUTS0 级别,只绘制外部国家边界。这可能吗?我试过 st_union 但这会聚集到欧盟外部边界,删除所有边界。
目前我的代码如下:
#read shapefile
EU.sf <- st_read("/ref-nuts-2021-01m.shp/NUTS_RG_01M_2021_3035_LEVL_1.shp/NUTS_RG_01M_2021_3035_LEVL_1.shp")
#plot without oversea territories
EUmap <- tm_shape(st_union(subset(EU.sf,
NUTS_ID != "FRY" &
NUTS_ID != "PT2" &
NUTS_ID != "PT3" &
NUTS_ID != "ES7" &
CNTR_CODE != "TR"
))) +
tm_borders()
谢谢!
我不太清楚您的预期结果,但看起来 NUTS1 文件中的 CNTR_CODE
变量包含与 NUTS0 边界等效的国家/地区代码。如果是这种情况,您可以使用 dplyr::count()
组合 NUTS1 文件中具有相同 CNTR_CODE
的所有多边形。
请注意,在此示例中,我从此处下载了边界的 geojson:https://gisco-services.ec.europa.eu/distribution/v1/nuts-2021.html
library(sf)
library(tidyverse)
tmp <- tempfile()
download.file("https://gisco-services.ec.europa.eu/distribution/v2/nuts/geojson/NUTS_RG_01M_2021_3035_LEVL_1.geojson", tmp)
nuts1 <- read_sf(tmp)
nuts_agg <- nuts1 %>%
filter(!NUTS_ID %in% c("FRY", "PT2", "PT3", "ES7") & CNTR_CODE != "TR") %>%
count(CNTR_CODE)
nuts_agg %>%
ggplot() +
geom_sf()