查找重叠圆内点的坐标

Find coordinates of points within overlapping circles

假设我在地球上有很多(经度、纬度)点(例如 1,000,000 点)。然后我 围绕每个点画一个圆圈,并想在其中找到一个新点 每个重叠区域。现在我对 (lon,lat) 坐标感兴趣 新点数。

下面给出了我想要实现的目标的说明:

# Original points (3 points)
lon <- c(6.3, 6.9, 6.9)
lat <- c(53, 53.1, 52.4)
df <- data.frame(lat = lat, lon = lon, r = .5) 

现在我想创建一个新的 data.frame,在重叠的圆圈内有 (lon,lat) 点:

# Example of new points within overlapping areas
df_new <- data.frame(
  lat = c(52.4, 53.1, 53, 53, 52.6, 52.75, 52.75),
  lon = c(6.9, 6.9, 6.3, 6.6, 6.5, 6.65, 7)
)

我怎样才能做到这一点?红点的确切位置无关紧要,唯一的限制是红点应该在交叉点内。我更喜欢 data.table 解决方案(而不是 sf 或 sp)。或者是否可以使用 Voronoi 图解决此问题?

reprex package (v1.0.0)

于 2021-04-26 创建

这可能不是您想要的,但可能对您有所帮助。下面的代码在 50 公里的 df 中的每个点周围获取缓冲区,找到重叠的几何图形和 df_new 中位于:

中的点
library(dplyr)
library(purrr)
library(sf)

lon <- c(6.3, 6.9, 6.9)
lat <- c(53, 53.1, 52.4)
df <- data.frame(lat = lat, lon = lon, r = .5) 

df_new <- data.frame(
  lat = c(52.4, 53.1, 53, 53, 52.6, 52.75, 52.75),
  lon = c(6.9, 6.9, 6.3, 6.6, 6.5, 6.65, 7)
) %>%
  st_as_sf(coords = c("lon", "lat"), crs = 4326) 


circle_df <- df %>%
  st_as_sf(coords = c("lon", "lat"), crs = 4326) %>%
  st_transform(3035) %>%
  st_buffer(dist = units::set_units(50, "kilometers"))


in_intersection <- st_intersection(circle_df) %>% 
  filter(n.overlaps == 2) %>%
  st_transform(4326) %>%
  st_within(df_new, .) %>%
  map_lgl(is_empty) %>%
  "!"() %>%
  which() %>%
  slice(df_new, .) 

plot(st_geometry(circle_df %>% st_transform(4326)))
plot(st_geometry(in_intersection), add = TRUE)

我不确定如何在经度和纬度上距离不同的点周围画圆(那不是圆,而是某种椭圆)。您可以尝试做的是通过从点 (lon, lat)(lon, lat-r) 获取距离(一种方法)并将该距离传递给缓冲区来近似半径。

df <- df %>% mutate(lat1 = lat - r) 
df1 <- df %>% st_as_sf(coords = c("lon", "lat"), crs = 4326)  
df2 <- df %>% st_as_sf(coords = c("lon", "lat1"), crs = 4326)   
d <- st_distance(df1, df2, by_element = TRUE)

circle_df <- df1 %>%
  st_transform(3035) %>%
  st_buffer(dist = d) 

并从这里继续上面的例子。我不确定它的可扩展性如何(你有很多积分)。

编辑

circle_df <- df %>%
  st_as_sf(coords = c("lon", "lat"), crs = 4326) %>%
  st_transform(3035) %>%
  st_buffer(dist = units::set_units(50, "kilometers"))

points_within <- st_intersection(circle_df) %>%
  st_centroid()

df_new <- points_within %>%
  st_transform(4326) %>%
  st_coordinates() %>%
  as_tibble() %>%
  setNames(c("lon", "lat"))

plot(st_geometry(circle_df))
plot(st_geometry(points_within), add = TRUE)

如果您只想在交叉点添加点,请在 st_centroid() 之后添加 filter(n.overlaps > 1)