I am interested in creating the minimum possible polygon around a set of nearly parallel cross sections. For example:
mls <- st_multilinestring(list(rbind(c(2,2),c(1,3)),
rbind(c(0,0),c(1,1),c(2,1)),
rbind(c(3,4),c(0,4))))
plot(mls)
I know there's the function st_convex_hull
but that doesn't accomplish what I want because it doesn't generate the minimum possible polygon.
I came up with almost a solution, like this:
mls %>% st_cast(to = "MULTIPOINT") %>%
st_cast(to = "POLYGON") %>%
st_simplify() %>%
plot()
Unfortunately, this only produces the desired output for this simple case. But it quickly falls apart with more lines. Here's example bad output:
mls2 <- st_multilinestring(list(rbind(c(2,2),c(1,3)),
rbind(c(0,0),c(1,1),c(2,1)),
rbind(c(3,4),c(0,4)),
rbind(c(1,10),c(-1,12))))
plot(mls2)
mls2 %>% st_cast(to = "MULTIPOINT") %>%
st_cast(to = "POLYGON") %>%
st_simplify() %>%
plot()
One idea I had was to pair adjacent lines and generate a polygon for each pair and then merge those polygons, but that feels cumbersome.