This function, as follows from the title, tries to guess the polygon centerline by connecting the most distant points from each other. First, it finds the point most distant from the polygon's centroid, then it searches for a second point, which is most distant from the first. The line connecting these two points will be the desired centerline.
Arguments
- input
sf,sfcorSpatVectorpolygons object- skeleton
NULL(default) orcnt_skeleton()output. IfNULLthen polygon's skeleton would be estimated in the background using specified parameters (see inherit params below).- return_geos
FALSE(default). A logical flag that controls whether thegeos_geometryshould be returned.- ...
Arguments passed on to
cnt_skeletonkeepnumeric, proportion of points to retain (0.05-5.0; default 0.5). See Details.
methodcharacter, either
"voronoi"(default) or"straight", or just the first letter"v"or"s". See Details.
Examples
library(sf)
library(geos)
lake <-
sf::st_read(
system.file("extdata/example.gpkg", package = "centerline"),
layer = "lake",
quiet = TRUE
) |>
geos::as_geos_geometry()
# Find lake's centerline
lake_centerline <- cnt_path_guess(input = lake, keep = 1)
# Plot
plot(lake)
plot(lake_centerline, col = "firebrick", lwd = 2, add = TRUE)