我想使用sf
来确定哪些people
位于任何cities
的5km范围内。在本例中,people
1和2应返回“Yes”。它们分别位于罗利和格林斯伯勒的5公里范围内。3不在这些城市的5公里范围内。
(This是一个突出真实的用例的玩具示例。)
library(tidyverse)
library(sf)
cities <- data.frame(city = c("Raleigh", "Greensboro", "Wilmington"),
x = c(-78.633333, -79.819444, -77.912222),
y = c(35.766667, 36.08, 34.223333)) %>%
st_as_sf(coords = c("x", "y"), crs = 4326) %>%
st_transform(2264)
people <- data.frame(person = c(1:3),
x = c(-78.634899, -79.821140, -103.236804),
y = c(35.766266, 36.077911, 30.551109)) %>%
st_as_sf(coords = c("x", "y"), crs = 4326) %>%
st_transform(2264)
# adapted toy example from
# https://community.rstudio.com/t/sf-function-that-can-find-all-available-polygones-to-a-point-within-a-certain-radius/114318/2
期望输出:
# A tibble: 3 × 2
person insideRad
<dbl> <chr>
1 1 Yes
2 2 Yes
3 3 No
或者:
# A tibble: 9 × 3
person city insideRad
<dbl> <chr> <chr>
1 1 Raleigh Yes
2 1 Greensboro No
3 1 Wilmington No
4 2 Raleigh No
5 2 Greensboro Yes
6 2 Wilmington No
7 3 Raleigh No
8 3 Greensboro No
9 3 Wilmington No
2条答案
按热度按时间ccgok5k51#
考虑这段代码;它的作用是:
x6h2sr282#
从OP中提供的玩具示例链接中获得灵感:
我不认为我的争吵是有效的,但它返回: