-
Notifications
You must be signed in to change notification settings - Fork 568
/
polylabel.py
42 lines (33 loc) · 1.27 KB
/
polylabel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Provides functions for finding the pole of inaccessibility for a given polygon."""
from shapely._geometry import get_point
from shapely.constructive import maximum_inscribed_circle
def polylabel(polygon, tolerance=1.0):
"""Find pole of inaccessibility for a given polygon.
Based on Vladimir Agafonkin's https://github.com/mapbox/polylabel
Parameters
----------
polygon : shapely.geometry.Polygon
Polygon for which to find the pole of inaccessibility.
tolerance : int or float, optional
`tolerance` represents the highest resolution in units of the
input geometry that will be considered for a solution. (default
value is 1.0).
Returns
-------
shapely.geometry.Point
A point representing the pole of inaccessibility for the given input
polygon.
Raises
------
shapely.errors.TopologicalError
If the input polygon is not a valid geometry.
Example
-------
>>> from shapely import LineString
>>> polygon = LineString([(0, 0), (50, 200), (100, 100), (20, 50),
... (-100, -20), (-150, -200)]).buffer(100)
>>> polylabel(polygon, tolerance=0.001)
<POINT (59.733 111.33)>
"""
line = maximum_inscribed_circle(polygon, tolerance)
return get_point(line, 0)