Need help with label_centerlines?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

152 Stars 40 Forks MIT License 28 Commits 4 Opened issues


python tool to extract smoothed centerlines from polygons

Services available


Need anything else?

Contributors list

# 272,870
25 commits
# 251,712
1 commit



This tool runs with Python 3.6 and reads Polygon/MultiPolygon datasets such as i.e. the

geographic regions
_ from
Natural Earth
_ and extracts smoothed centerlines for better label placement. This method is used to create the label layer of
EOX Maps


geographic regions
: .. _

Natural Earth
: .. _
EOX Maps

To do so, it a

Voronoi diagram
_ is created to get the polygon skeleton where the skeleton centerline is selected and smoothed.


Voronoi diagram

.. figure:: img/centerline.gif


  1. Extract outline.
  2. Segmentize outline to get more evenly distributed outline points.
  3. Extract points.
  4. If there are too many points, simplify the segmentized outline and Extract points again.
  5. Create Voronoi diagram.
  6. Select all Voronoi edges which are inside the source polygon.
  7. Determine the best line.
  8. Smooth line.


clone repository and run

.. code-block:: shell

pip install -r requirements.txt
python install


.. code-block:: shell

$ label_centerlines --help

Usage: label_centerlines [OPTIONS] INPUT_PATH OUTPUT_PATH

Read features, convert to centerlines and write to output.

Multipart features (MultiPolygons) from input will be converted to singlepart features, i.e. all output features written will be LineString geometries, not MultiLineString geometries.

Options: --version Show the version and exit. --segmentize_maxlen FLOAT Maximum segment length for polygon borders. (default: 0.5) --max_points INTEGER Number of points per geometry allowed before simplifying. (default: 3000) --simplification FLOAT Simplification threshold. (default: 0.05) --smooth INTEGER Smoothness of the output centerlines. (default: 5) --output_driver [GeoJSON|GPKG] Output format. (default: 'GeoJSON') --verbose show information on processed features --debug show debug log messages --help Show this message and exit.


.. code-block::

>>> from label_centerlines import get_centerline
>>> help(get_centerline)

get_centerline(geom, segmentize_maxlen=0.5, max_points=3000, simplification=0.05, smooth_sigma=5) Return centerline from geometry.


geom : shapely Polygon or MultiPolygon segmentize_maxlen : Maximum segment length for polygon borders. (default: 0.5) max_points : Number of points per geometry allowed before simplifying. (default: 3000) simplification : Simplification threshold. (default: 0.05) smooth_sigma : Smoothness of the output centerlines. (default: 5)


geometry : LineString or MultiLineString


CenterlineError : if centerline cannot be extracted from Polygon TypeError : if input geometry is not Polygon or MultiPolygon


MIT License

Copyright (c) 2015, 2016, 2017, 2018

EOX IT Services

.. _

EOX IT Services

(see LICENSE file for more details)

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.