从一组状态创建区域纬度、长数据框 [英] Create regional lat, long dataframe from group of states
问题描述
我一直在使用 urbnmapr
制作我的所有地图,它包含用于绘制美国各州的漂亮边界.我现在需要几个州的外边界来制作区域地图,并且正在寻找一种方法来过滤数据框以仅包含外边界.
I have been using urbnmapr
for all of my mapmaking and it contains nice borders for mapping US states. I now need the outer border of a few states to make a regional map and am looking for a way to filter the dataframe to include only the outer borders.
我将使用此外边框来屏蔽光栅图像.我工作的地区是
I will use this outer border to mask a raster image. The region I am working with is
filter(urbnmapr::states, state_name %in% c("South Dakota", "Nebraska", "Iowa", "Minnesota",
"Missouri", "Michigan", "Indiana", "Illinois",
"Wisconsin", "Kansas", "Ohio", "North Dakota"))
接受任何能给我一个对象的想法,我可以用它来掩盖该区域的栅格.
Open to any ideas that will give me an object I can use to mask a raster of this region.
推荐答案
使用 urbnmapr
和 sf
.
在仅您想要的状态的 sf 对象上使用 st_union()
将为您提供外部边界.
Using st_union()
on the sf object of only the states you want will give you the exterior borders.
我认为 sf
对象可用于遮罩/裁剪光栅对象.
I think sf
objects can be used to mask/crop raster objects.
library(urbnmapr)
library(tidyverse)
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
states_all <- get_urbn_map(map = 'states', sf = TRUE)
my_states_vec <- c("South Dakota", "Nebraska", "Iowa", "Minnesota",
"Missouri", "Michigan", "Indiana", "Illinois",
"Wisconsin", "Kansas", "Ohio", "North Dakota")
my_states <- states_all %>%
filter(state_name %in% my_states_vec) %>%
st_union()
head(my_states)
#> Geometry set for 1 feature
#> geometry type: MULTIPOLYGON
#> dimension: XY
#> bbox: xmin: -340177.8 ymin: -950695.4 xmax: 1627432 ymax: 498098.3
#> projected CRS: US National Atlas Equal Area
#> MULTIPOLYGON (((1422979 -227154.2, 1423979 -225...
ggplot(my_states) +
geom_sf(fill = NA)
由 reprex 包 (v0.3.0) 于 2020 年 12 月 10 日创建上>
Created on 2020-12-10 by the reprex package (v0.3.0)
这篇关于从一组状态创建区域纬度、长数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!