shapely <-> paths
This commit is contained in:
parent
7c86ce20d2
commit
c3ca0b65bc
|
@ -9,7 +9,9 @@ from .paths import (
|
||||||
load_paths,
|
load_paths,
|
||||||
path_length,
|
path_length,
|
||||||
paths_length,
|
paths_length,
|
||||||
|
paths_to_shapely,
|
||||||
quadratic_path,
|
quadratic_path,
|
||||||
|
shapely_to_paths,
|
||||||
simplify_path,
|
simplify_path,
|
||||||
simplify_paths,
|
simplify_paths,
|
||||||
sort_paths,
|
sort_paths,
|
||||||
|
|
23
axi/paths.py
23
axi/paths.py
|
@ -156,3 +156,26 @@ def expand_quadratics(path):
|
||||||
else:
|
else:
|
||||||
raise Exception('invalid point: %r' % point)
|
raise Exception('invalid point: %r' % point)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def paths_to_shapely(paths):
|
||||||
|
# TODO: Polygons for closed paths?
|
||||||
|
return geometry.MultiLineString(paths)
|
||||||
|
|
||||||
|
def shapely_to_paths(g):
|
||||||
|
if isinstance(g, geometry.Point):
|
||||||
|
return []
|
||||||
|
elif isinstance(g, geometry.LineString):
|
||||||
|
return [list(g.coords)]
|
||||||
|
elif isinstance(g, (geometry.MultiPoint, geometry.MultiLineString, geometry.MultiPolygon, geometry.collection.GeometryCollection)):
|
||||||
|
paths = []
|
||||||
|
for x in g:
|
||||||
|
paths.extend(shapely_to_paths(x))
|
||||||
|
return paths
|
||||||
|
elif isinstance(g, geometry.Polygon):
|
||||||
|
paths = []
|
||||||
|
paths.append(list(g.exterior.coords))
|
||||||
|
for interior in g.interiors:
|
||||||
|
paths.extend(shapely_to_paths(interior))
|
||||||
|
return paths
|
||||||
|
else:
|
||||||
|
raise Exception('unhandled shapely geometry: %s' % type(g))
|
||||||
|
|
Loading…
Reference in New Issue