Skip to main content

Calculate the centerline of a polygon

Project description

https://travis-ci.org/fitodic/centerline.svg?branch=master https://coveralls.io/repos/github/fitodic/centerline/badge.svg?branch=master Version

Calculate the centerline of a polygon.

Roads, rivers and similar linear structures are often represented by long and complex polygons. Since one of the most important attributes of a linear structure is its length, extracting that attribute from a polygon can prove to be more or less difficult.

Installation:

You can download the package from PyPI:

$ pip install centerline

This package has several dependencies, including Numpy, Scipy and GDAL/OGR.

If you are installing these packages in the virtual environement, make sure you have all the necessary dependencies on your system. Furthermore, after installing GDAL locate the GDAL headers:

$ whereis gdal
gdal: /usr/include/gdal /usr/share/gdal

and set the include path using the following environment variables:

$ export CPLUS_INCLUDE_PATH=/usr/include/gdal/
$ export C_INCLUDE_PATH=/usr/include/gdal/

After that, you can proceed to installing GDAL in the virtual environment.

It is important to note that the versions of GDAL installed globally and in the virtual environment should match!

For more info, visit Stack Exchange.

Usage:

If you are planning on using this package inside of your own code, just type:

>>> from centerline import Centerline

However, if you just want to convert a Shapefile full of polygons into a Shapefile full of centerlines, use the command line tool:

$ shp2centerline INPUT_PATH.shp OUTPUT_PATH.shp [BORDER_DENSITY]

The BORDER_DENSITY parameter is optional. If not specified, the default value is 0.5.

Warning: The INPUT_PATH.shp file needs to have a column called id with unique values or the script will fail to execute successfully.

References:

When defining the density factor, one has to take into account the coordinate system defined in the Shapefile. The script was designed to handle metric coordinate systems, so the density factor is by default 0.5 (meters). For instance, if the value is set to 0.5 m, it basically places additional points on the border at the distance of 0.5 m from each other. If the user doesn’t define the value (see Usage), the script uses the default value. If the value is a negative number, it will be converted into a positive number.

It appears that the Voronoi function available in the SciPy module does not handle large coordinates very well. Since most of the coordinates are large numbers, a bounding box is needed to determine the minimal X and Y coordinates, i.e. the bottom left corner of the bounding box. These values are then used for coordinate reduction. Once the Voronoi diagram is created the coordinates are returned to their non-reduced form before creating LineStrings.

Example Screenshot

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

centerline-0.2.1.tar.gz (128.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

centerline-0.2.1-py27-none-any.whl (8.6 kB view details)

Uploaded Python 2.7

File details

Details for the file centerline-0.2.1.tar.gz.

File metadata

  • Download URL: centerline-0.2.1.tar.gz
  • Upload date:
  • Size: 128.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for centerline-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4cbc562ab4ae12932af6b9731d5c6719a363f230998206711041e5cf23286542
MD5 cd33868325d8d68ec0f14c6d76bbd4aa
BLAKE2b-256 df197492f9a9438191d7351c2a0e6dc5a26c5a46e659b27c091b7c8dcfe1401f

See more details on using hashes here.

File details

Details for the file centerline-0.2.1-py27-none-any.whl.

File metadata

File hashes

Hashes for centerline-0.2.1-py27-none-any.whl
Algorithm Hash digest
SHA256 a244b4409ead8d7a79b42cdb1daa8f5aaf65bdd7603d1ff4f81b00323ab62e9f
MD5 a2306360865aff0196a770aeda44b0cb
BLAKE2b-256 bcc2588afac9875e5e0fe0f7dd68608f6bd09534a0ec5dbd33ec50eb25621e50

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page