def get_intersections(roads):
"""Calculates the intersection points of all roads
:param roads: List of shapely geometries representing road segments
"""
intersections = []
for road1, road2 in itertools.combinations(roads, 2):
if road1.intersects(road2):
intersection = road1.intersection(road2)
if 'Point' == intersection.type:
intersections.append(intersection)
elif 'MultiPoint' == intersection.type:
intersections.extend([pt for pt in intersection])
elif 'MultiLineString' == intersection.type:
multiLine = [line for line in intersection]
first_coords = multiLine[0].coords[0]
last_coords = multiLine[len(multiLine)-1].coords[1]
intersections.append(Point(first_coords[0], first_coords[1]))
intersections.append(Point(last_coords[0], last_coords[1]))
elif 'GeometryCollection' == intersection.type:
intersections.extend(get_intersections(intersection))
# The unary_union removes duplicate points
unioned = unary_union(intersections)
# Ensure the result is a MultiPoint, since calling functions expect an iterable
if 'Point' == unioned.type:
unioned = MultiPoint([unioned])
return unioned
generate_training_input.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录