查找一组点和一组多龙组之间的相交
我正在尝试使用URBNMAPR软件包将县FIPS代码分配给纬度,经度数据。我将两个CRS都设置为2163,这似乎是urbnmapr中的默认设置。但是,urbnmapr几何形状的值与我的观点的值大不相同,这是行不通的。我的所有观点最终都以相同的FIPS代码。
library(urbnmapr)
counties_sf <- get_urbn_map(map = "counties", sf = TRUE)
head(counties_sf)
我的观点更典型:
df <- data.frame(value = c(5, 7, 8), lat = c(-100.92, -78.09, -96.96),
lon = c(35.35, 37.71, 38.52))
df_sf <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326) %>%
st_transform(crs = 2163)
head(df_sf)
我错过了什么来将这些要点分配给多龙的正确county_fips值?
编辑:使用ST_TRANSFORM
回答了初始问题,并在同一CRS中获得了集合,我仍然不确定为什么它们不会融合在一起。
fips_place <- sf::st_join(df_sf, counties_sf)
I am trying to use the urbnmapr package to assign county FIPS codes to latitude, longitude data. I have set both CRS to 2163, which seems to be the default setting in urbnmapr. However, the values of the urbnmapr geometries are very different from the values of my points and this doesn't work. All of my points end up with the same FIPS code.
library(urbnmapr)
counties_sf <- get_urbn_map(map = "counties", sf = TRUE)
head(counties_sf)
My points are more typical:
df <- data.frame(value = c(5, 7, 8), lat = c(-100.92, -78.09, -96.96),
lon = c(35.35, 37.71, 38.52))
df_sf <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326) %>%
st_transform(crs = 2163)
head(df_sf)
If I set the CRS to any other value for the urbnmapr set, the geometry values do not change. What am I missing to get these points assigned to the correct county_fips value for the multipolygons?
Edit: Using st_transform
answered the initial question and got the sets in the same CRS, I'm still not sure why they won't come together.
fips_place <- sf::st_join(df_sf, counties_sf)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论