简体   繁体   English

如何为 R 中的点坐标构建 Voronoi 多边形?

[英]How to build Voronoi Polygons for point coordinates in R?

I have various points (2000+) for observation stations in the alps.对于阿尔卑斯山的观测站,我有各种积分(2000+)。 I would like to use them to represent the closest geographic area, that is not closer to another observation station.我想用它们来代表最近的地理区域,即不靠近另一个观测站。 I have done some research, and think that using Varanoi polygons may be the best way to do this.我做了一些研究,并认为使用 Varanoi 多边形可能是最好的方法。

After having attempting to build these in R, the polygon plot does not quite match my graphing in R.在尝试在 R 中构建这些之后,多边形 plot 与我在 R 中的图形不太匹配。

I have attached the sample data points I am experimenting with, as well as the two images that show the dissimilar graphing of the points.我附上了我正在试验的样本数据点,以及两个显示不同点图形的图像。

What do I need to be do differently to make sure that the points line up?我需要做些什么来确保点对齐?

Points:要点:

Longitude:
15.976667 12.846389 14.457222 13.795556  9.849167 16.055278 13.950833 15.666111  9.654722 15.596389 13.226667 15.106667 13.760000 12.226111  9.612222 17.025278  9.877500 15.368056 13.423056 12.571111 16.842222 13.711667 14.003056 12.308056 13.536389

Latitude:
48.40167 48.14889 47.56778 46.72750 47.45833 48.04472 47.82389 47.49472 47.35917 48.64917 48.25000 48.87139 47.87444 47.42806 47.20833 47.77556 47.40389 47.87583 47.53750 46.77694 47.74250 46.55000 48.37611 47.38333 47.91833

Pictures: Map of the 25 sample points in Leaflet:图片:Leaflet 中 25 个采样点的 Map: 在此处输入图像描述

Voronoi plot:沃罗诺伊 plot: 在此处输入图像描述

Clearly these two are not the same images, so I must be doing something wrong.显然这两个不是相同的图像,所以我一定做错了什么。 Here's the code I'm using to generate the Voronoi plot and the leaflet map.这是我用来生成 Voronoi plot 和 leaflet map 的代码。

meta25%>% 
  st_as_sf(coords = c("Longitude", "Latitude"),
           crs = sp::CRS("+proj=longlat +datum=WGS84")) %>% 
  mapview()

m1 = matrix(meta25$Longitude,meta25$Latitude,ncol=2,nrow=25) %>% st_multipoint()
voronoi_grid <- st_voronoi(m1)
plot(voronoi_grid, col = NA)
plot(m1, add = TRUE, col = "blue", pch = 16)

I'm not sure what the problem is, but the matrix is not necessary.我不确定问题是什么,但矩阵不是必需的。 Stick to sf objects and you should be fine.坚持sf对象,你应该没问题。


library(tidyverse)
library(sf)


# create pts from lat & lon data
pts <- tibble(latitude = y, longitude = x) %>%
  st_as_sf(coords = c('latitude', 'longitude')) %>%
  st_set_crs(4326)

# voronoi of pts
vor <- st_voronoi(st_combine(pts))

head(vor)
#> Geometry set for 1 feature 
#> Geometry type: GEOMETRYCOLLECTION
#> Dimension:     XY
#> Bounding box:  xmin: 2.199166 ymin: 39.13694 xmax: 24.43833 ymax: 56.28445
#> Geodetic CRS:  WGS 84
#> GEOMETRYCOLLECTION (POLYGON ((2.199166 49.37841...

# st_voronoi returns a GEOMETRYCOLLECTION,
#  some plotting methods can't use a GEOMETRYCOLLECTION.
#  this returns polygons instead
vor_poly <- st_collection_extract(vor)

head(vor_poly)
#> Geometry set for 6 features 
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 2.199166 ymin: 39.13694 xmax: 18.32787 ymax: 56.28445
#> Geodetic CRS:  WGS 84
#> First 5 geometries:
#> POLYGON ((2.199166 49.37841, 2.199166 56.28445,...
#> POLYGON ((9.946349 39.13694, 2.199166 39.13694,...
#> POLYGON ((18.32787 39.13694, 11.64381 39.13694,...
#> POLYGON ((9.794868 47.23828, 9.766296 47.38061,...
#> POLYGON ((5.225657 56.28445, 9.393793 56.28445,...

plot(pts, col = 'blue', pch = 16)
plot(vor_poly, add = T, fill = NA)

Created on 2021-04-05 by the reprex package (v0.3.0)代表 package (v0.3.0) 于 2021 年 4 月 5 日创建

Thanks everyone for your help, not sure if it got quite to where I was looking for.感谢大家的帮助,不知道它是否到达了我要找的地方。 I've since adapted the answer from here: Creating bordering polygons from spatial point data for plotting in leaflet我已经从这里调整了答案: 从空间点数据创建边界多边形以在 leaflet 中绘图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM