gpt4 book ai didi

r - 来自 R 中经纬度点簇的多边形

转载 作者:行者123 更新时间:2023-12-04 00:29:33 26 4
gpt4 key购买 nike

我正在尝试从将接触所有外部点的点边界集群创建多边形。任何有助于改进我的代码的帮助将不胜感激。

library(dplyr)
library(sf)
df<- read.table(text ="lon lat
74.03687 30.17482
74.23605 30.23773
74.24127 29.95988
74.29211 30.07575
74.25612 30.17687
74.15972 30.06242
74.06484 30.11025
74.36046 30.02749
74.08133 30.01889
74.26168 30.16881
73.91083 30.01378
74.00881 30.07585
74.40638 29.97712
74.34974 30.22231
74.20501 30.11133
74.18108 30.01113
74.00717 30.11362
73.94891 30.03807
74.18977 30.14367
74.18857 30.13621
74.19862 30.15222
74.19376 30.13425",header= T)
polygon <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326) %>%
summarise(geometry = st_combine(geometry)) %>%
st_cast("POLYGON")
plot(polygon)

在单个多边形中需要像蓝线这样的输出。
enter image description here

最佳答案

我建议使用 concaveman 包来完成这个任务:

library(concaveman)

pnts <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326)
polygon <- concaveman(pnts)

plot(polygon, reset = FALSE)
plot(pnts, add = TRUE)

enter image description here

关于r - 来自 R 中经纬度点簇的多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53440909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com