Я не уверен, что понимаю, что именно вы хотите: расстояние до самой дальней точки (это то, что вы спрашиваете) или координаты самой дальней точки (это то, что предоставляется ответом, на который вы указываете).
Вот решение для расчета расстояния (и его можно легко изменить, чтобы извлечь координаты)
# This is an example for one polygon.
# NB the polygon is the same as in the answer pointed to in the question
library(sf)
sfPol <- st_sf(st_sfc(st_polygon(list(cbind(c(5,4,2,5),c(2,3,2,2))))))
center <- st_centroid(sfPol)
vertices <- st_coordinates(sfPol)[,1:2]
vertices <- st_as_sf(as.data.frame(vertices), coords = c("X", "Y"))
furthest <- max(st_distance(center, vertices))
furthest
## [1] 1.699673
# You can adapt this code into a function that will work
# for multiple polygons
furthest <- function(poly) {
# tmpfun find the furthest point from the centroid of one unique polygon
tmpfun <- function(x) {
center <- st_centroid(x)
vertices <- st_coordinates(x)[,1:2]
vertices <- st_as_sf(as.data.frame(vertices), coords = c("X", "Y"))
furthest <- max(st_distance(center, vertices))
return(furthest)
}
# We apply tmpfun on each polygon
return(lapply(st_geometry(poly), tmpfun))
}
poly1 <- cbind(c(5,4,2,5),c(2,3,2,2))
poly2 <- cbind(c(15,10,8,15),c(5,4,12,5))
sfPol <- st_sf(st_sfc(list(st_polygon(list(poly1)),
st_polygon(list(poly2)))))
furthest(sfPol)
## [[1]]
## [1] 1.699673
##
## [[2]]
## [1] 5.830952
person
Gilles
schedule
25.01.2018