将多边形投射到 POINT(从而获取顶点),然后计算质心的距离应该可以工作。就像是:
library(sf)
# build a test poly
geometry <- st_sfc(st_polygon(list(rbind(c(0,0), c(1,0), c(1,3), c(0,0)))))
pol <- st_sf(r = 5, geometry)
# compute distances
distances <- pol %>%
st_cast("POINT") %>%
st_distance(st_centroid(pol))
distances
#> [,1]
#> [1,] 1.201850
#> [2,] 1.054093
#> [3,] 2.027588
#> [4,] 1.201850
# maximum dist:
max_dist <- max(distances)
max_dist
#> [1] 2.027588
# plot to see if is this correct: seems so.
plot(st_geometry(pol))
plot(st_centroid(pol), add = T)
plot(st_cast(pol, "POINT")[which.max(distances),],
cex =3, add = T, col = "red")
Run Code Online (Sandbox Code Playgroud)

由于第一个和最后一个顶点相同,您会得到两次相同的距离,但由于您对最大值感兴趣,所以这应该不重要。
华泰
| 归档时间: |
|
| 查看次数: |
2194 次 |
| 最近记录: |