Learn R Programming

⚠️There's a newer version (0.2.2) of this package.Take me there.

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)

Copy Link

Version

Install

install.packages('centerline')

Monthly Downloads

268

Version

0.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Anatoly Tsyplenkov

Last Published

March 16th, 2025

Functions in centerline (0.1)

cnt_path

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

Guess polygon's centerline
cnt_skeleton

Create a skeleton of a closed polygon object