Giter VIP home page Giter VIP logo

label_centerlines's Introduction

label_centerlines

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.

To do so, it a 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

clone repository and run

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

CLI

$ 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.

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)
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)

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

(see LICENSE file for more details)

label_centerlines's People

Contributors

styxman avatar ungarj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.