def bounded_segments(lines, bounding_box, cut_segment=True):
"""
Extract the bounded segments from a list of lines
:param lines: a list of LineString
:param bounding_box: the bounding coordinates in (minx, miny, maxx, maxy)
or Polygon instance
:return: a list of bounded segments
"""
if isinstance(bounding_box, Polygon):
bbox = bounding_box
else:
bbox = box(bounding_box[0], bounding_box[1],
bounding_box[2], bounding_box[3])
segments = []
for line in lines:
if line.intersects(bbox):
if cut_segment:
segments.append(line.intersection(bbox))
else:
segments.append(line)
return segments
评论列表
文章目录