centerline
The centerline
R package simplifies the extraction of linear features
from complex polygons, such as roads or rivers, by computing their
centerlines (or median-axis) using Voronoi diagrams. It uses the
super-fast geos
library in the background.
Installation
You can install the development version of centerline
from
GitHub with pak
:
# install.packages("pak")
pak::pak("atsyplenkov/centerline")
Examples for closed geometries
At the heart of this package is the cnt_skeleton
function, which
efficiently computes the skeleton of closed 2D polygonal geometries. The
function uses
geos::geos_simplify
by default to keep the most important nodes and reduce noise from the
beginning. However, it has option to densify the amount of points using
geos::geos_densify
,
which can produce more smooth results. Otherwise, you can set the
parameter keep = 1
to work with the initial geometry.
library(sf)
library(centerline)
lake <-
sf::st_read(
system.file("extdata/example.gpkg", package = "centerline"),
layer = "lake",
quiet = TRUE
)
# Original
lake_skeleton <-
cnt_skeleton(lake, keep = 1)
# Simplified
lake_skeleton_s <-
cnt_skeleton(lake, keep = 0.1)
# Densified
lake_skeleton_d <-
cnt_skeleton(lake, keep = 2)