本文介绍使用Python shapely库完成地图分区的基本原理。地图分区的具体内容是:输入道路网,根据路网将地图分割为多个互不重叠的区域。
将路网数据构建为Shapely的线对象:
from shapely.geometry import MultiLineString
lines = [
((0, 0), (1, 1)),
((0, 0), (0, 1)),
((0, 1), (1, 1)),
((1, 1), (1, 0)),
((1, 0), (0, 0)),
((0, 2), (1,0))
]
road = MultiLineString(lines)
road
road_poly = road.buffer(0.001)
from shapely.geometry import box
region = box(0.0, 0.0, 2.0, 2.0)