Skip to content

Latest commit

 

History

History
82 lines (55 loc) · 3.11 KB

File metadata and controls

82 lines (55 loc) · 3.11 KB

shapely-polyskel

PyPI - Status PyPI - Version PyPI - Python Version

A straight skeleton

Note

This package is a fork of an implementation written by Ármin Scipiades (Botffy). The original code can be found under the link.

This is a Python 3 implementation of the straight skeleton algorithm as described by Felkel and Obdržálek in their 1998 conference paper Straight skeleton implementation.

The algorithm itself is fairly dated, and shown to be incorrect for certain input polygons. This implementation is a bit crap, and does not really attempt to fix the algorithm. It works kinda okay for most real-life input (for example country contours or floor plans).

For a modern and excellent overview of the topic please refer to Stefan Huber's excellent Computing Straight Skeleton and Motorcycle Graphs: Theory and Practice.

Installation

shapely-polyskel is available on PyPI:

pip install shapely-polyskel

Usage

Basic example (skeletonize)

from shapely_polyskel import skeletonize

rectangle = [(40, 40), (40, 310), (520, 310), (520, 40)]
skeleton = skeletonize(polygon=rectangle)

Polygon with holes (skeletonize)

from shapely_polyskel import skeletonize

rectangle = [(40, 40), (40, 310), (520, 310), (520, 40)]
holes = [[(100, 100), (200, 100), (200, 150), (100, 150)]]
skeleton = skeletonize(polygon=rectangle, holes=holes)

Basic example (StraightSkeleton)

from shapely import Polygon
from shapely_polyskel import StraightSkeleton

# In the case of using 'StraightSkeleton', the direction of the polygon/hole
# points is not important.

polygon = Polygon(
    [(520, 40), (520, 310), (40, 310), (40, 40)],
    [[(100, 150), (200, 150), (200, 100), (100, 100)]],
)

straight_skeleton = StraightSkeleton(polygon=polygon)

# Returns the same list as 'skeletonize'
skeleton = straight_skeleton.straight_skeleton

source_points = straight_skeleton.source_points(points3d=False)
ridges = straight_skeleton.ridges()
sinks = straight_skeleton.sinks()

More examples can be found in the notebooks directory.

Forks & ports