Metadata-Version: 2.4
Name: bera_centerlines
Version: 2025.3.0
Summary: An advanced forest line feature analysis platform
Project-URL: Homepage, https://github.com/RichardQZeng/label_centerlines
Author-email: AppliedGRG <appliedgrg@gmail.com>, Richard Zeng <richardqzeng@gmail.com>
License: The MIT License (MIT)
        
        Copyright (c) 2015, 2016, 2017, 2018 EOX IT Services
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE.md
Keywords: BERA,Centerline
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Requires-Dist: click
Requires-Dist: fiona>=1.7.0
Requires-Dist: networkit>=11.0
Requires-Dist: networkx>=2.1
Requires-Dist: scipy>=0.17
Requires-Dist: shapely>=1.5
Requires-Dist: tqdm
Description-Content-Type: text/markdown

# label_centerlines

This tool runs with Python 3.6 and reads Polygon/MultiPolygon datasets
such as i.e. the [geographic
regions](http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_geography_regions_polys.zip)
from [Natural Earth](http://www.naturalearthdata.com/) and extracts
smoothed centerlines for better label placement. This method is used to
create the label layer of [EOX Maps](http://maps.eox.at).

To do so, it a [Voronoi
diagram](https://en.wikipedia.org/wiki/Voronoi_diagram) is created to
get the polygon skeleton where the skeleton centerline is selected and
smoothed.

![](img/centerline.gif)

Steps:

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.

## Installation

Networkit is added to speedup the path finding.

## Installation

clone repository and run

``` shell
pip install -r requirements.txt
python setup.py install
```

or by conda .. code-block:: shell conda install -c appliedgrg
label_centerline

## CLI

``` 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)
  --max_paths INTEGER             Number of longest paths used to create the 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.
```

## API

``` 
>>> 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, max_paths=5)
Return centerline from geometry.

Parameters:
-----------
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)
max_paths : Number of longest paths used to create the centerlines.
    (default: 5)

Returns:
--------
geometry : LineString or MultiLineString

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

## License

MIT License

Copyright (c) 2015, 2016, 2017, 2018 [EOX IT Services](https://eox.at/)

(see LICENSE file for more details)
