refactor c3nav.routing

This commit is contained in:
Laura Klünder 2016-12-03 19:09:39 +01:00
parent 575af6c06e
commit 834d6f0064
13 changed files with 381 additions and 364 deletions

View file

@ -0,0 +1,29 @@
from matplotlib.path import Path
from c3nav.routing.utils.base import assert_multipolygon
def polygon_to_mpl_paths(polygon):
"""
convert a shapely Polygon or Multipolygon to a matplotlib Path
:param polygon: shapely Polygon or Multipolygon
:return: matplotlib Path
"""
paths = []
for polygon in assert_multipolygon(polygon):
paths.append(linearring_to_mpl_path(polygon.exterior))
for interior in polygon.interiors:
paths.append(linearring_to_mpl_path(interior))
return paths
def linearring_to_mpl_path(linearring):
vertices = []
codes = []
coords = list(linearring.coords)
vertices.extend(coords)
vertices.append(coords[0])
codes.append(Path.MOVETO)
codes.extend([Path.LINETO] * (len(coords)-1))
codes.append(Path.CLOSEPOLY)
return Path(vertices, codes, readonly=True)