Learn R Programming

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) based on skeletons. It uses the super-fast geos library in the background and have bindings for your favorite spatial data library (sf, terra and geos).

Installation

# The easiest way to get centerline is to install it from CRAN:
install.packages("centerline")

# Or the development version from GitHub:
# 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)

cnt_skeleton() code

Copy Link

Version

Install

install.packages('centerline')

Monthly Downloads

528

Version

0.2.4

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Anatoly Tsyplenkov

Last Published

December 22nd, 2025

Functions in centerline (0.2.4)

cnt_path

Find the shortest path between start and end points within a polygon
geom_cnt

Plot centerline with ggplot2
cnt_path_guess

Guess polygon's centerline
geom_cnt_text

Plot label or text on centerline with ggplot2
cnt_skeleton

Create a skeleton of a closed polygon object