计算多段线之间的最大距离

Calculate Max Distance Between Polylines

有没有办法计算两条折线之间的最大距离?我目前正在使用 sf 包来获取最小距离,但我还需要最大距离,请参见下面的示例。

pts1<- data.frame(
  x= c(-103.485342, -103.482808),
  y = c(31.348758, 31.376947))
) %>% 
  sf::st_as_sf(coords = c("x","y"))

st_crs(pts1)<- "+init=epsg:2257"

pts2<- data.frame(
  x= c(-103.492822, -103.484231),
  y = c(31.348181, 31.377191))
) %>% 
  sf::st_as_sf(coords = c("x","y"))

st_crs(pts2)<- "+init=epsg:2257"

a <- pts1 %>% st_coordinates() %>% st_linestring()
b<- pts2 %>% st_coordinates() %>% st_linestring()

min_dist<-st_distance(a,b,by_element = T)

max_dist<- ???

谢谢

最大距离(在平面几何中)应该总是在两个顶点之间,因此转换为点,计算点 a 和点 b 之间的距离矩阵,并取最大值:

> max(st_distance(st_cast(st_sfc(b),"POINT"),st_cast(st_sfc(a),"POINT")))
[1] 0.0304592

注意这是沿着红色虚线的距离:

您的这两条线可能代表河岸之类的东西,您真正的问题是 "how wide is the river at its widest",在您的示例中,它位于最南端的两个点之间,但这是不同的问题 "what's the greatest distance between two lines".