比如这样的两个区域,我们想知道从蓝到绿、从绿到蓝都有哪些边
1 读取openstreetmap
import osmnx as ox
import geopandas as gpdG=ox.graph_from_place('Singapore',simplify=True,network_type='drive')ox.plot_graph(G)
2 得到对应的边的信息
nodes,edges=ox.graph_to_gdfs(G)
#得到新加坡graph的点和边对应的信息nodes
edges
3 新加坡subzone信息
https://beta.data.gov.sg/datasets/1749/view
import geopandas as gpd
sgsubzone=gpd.read_file('ura-mp19-subzone-no-sea-pl.geojson')
sgsubzone
#新加坡subzone 数据
4 找到穿插在两个区域间的边
subzeon1_ed=edges[edges.intersects(sgsubzone.loc[0].geometry)]
#和subzone 1 相交的边subzeon2_ed=edges[edges.intersects(sgsubzone.loc[1].geometry)]
##和subzone 2 相交的边len(subzeon1_ed),len(subzeon2_ed)
#(21, 46)inner_subzone=subzeon1_ed.merge(subzeon2_ed, left_index=True, right_index=True, how='inner')
#和subzone 1 相交的边 和 和subzone 2相交的边 的交集inner_subzone=inner_subzone.set_geometry('geometry_y')
#设置活跃geometryinner_subzone
5 可视化
ax=gpd.GeoSeries(sgsubzone.loc[0].geometry).plot(figsize=(15,10))
subzeon1_ed.plot(ax=ax,color='yellow')
gpd.GeoSeries(sgsubzone.loc[1].geometry).plot(ax=ax,color='green',alpha=0.4)
subzeon2_ed.plot(ax=ax,color='red')
inner_subzone.plot(ax=ax,color='purple',lw=10)
#绘图,两个subzone, 各自的路段, 相交的路段