仅在特定位置使用Osmnx时,无法从OSM获取正确的图形(Modena)

时间:2019-03-07 17:13:30

标签: openstreetmap networkx osmnx

我的目标是使用Osmnx和Networkx生成从A点到B点的路由。路线代表步行和骑车位移,所以我想忽略单向街道。

为了完成此任务,我使用了G = ox.graph_from_place(place, network_type='walk')这个参数,到目前为止,对于Barcelona(ES)和Cesena(IT)来说,一切都运转良好。

现在我正在尝试对Modena(IT)进行同样的操作,但是同时使用network_type='walk' network_type='cycle'时会得到不完整的图形(请参见png)。

获取完整的Modena图的唯一方法是不指定network_type参数,但是通过这样做,G中的边仍然带来值oneway = True。因此,路由是错误的,因为它考虑了单向街道。我尝试使用以下方法更改该值:

for u, v, key, data in G.edges(keys=True, data=True):
    data['oneway']=False 

我没有收到任何错误,但路由仍然不正确。 我在这里想念什么?

Modena graph with no roads in city centre expected routing vs wrong routing

编辑:附加了以下代码段:

  • 在不指定网络类型和图的情况下获取图形 红色的单向街道上它
  • 检索网络类型为“走”的图形并将其绘制
  • 列出丢失的OSMid并将它们绘制成洋红色

    place = {'city' : 'Modena', 'country' : 'Italia'}
    
    #--------SOME BASIC SETTINGS FOR PLOTTING------
    
    one_way = (0.863, 0.039, 0.173,1)
    two_way = (0.243, 0.243, 0.243,1)
    background = (0.973, 0.973, 0.973,1)
    
    
    #--------PLOT GRAPH WITHOUT SPECIFYING THE NETWORK TYPE AND GET THE OSMIDs---------
    
    G = ox.graph_from_place(place)
    
    osmid_no_network = list([data['osmid'] for u, v, key, data in G.edges(keys=True, data=True)])
    
    ec = [one_way if data['oneway'] else two_way for u, v, key, data in G.edges(keys=True, data=True)]
    
    fig, ax = ox.plot_graph(G, bgcolor=background,
    show=False, close=True, fig_height=11, fig_width=11, node_size = 0, edge_linewidth = 0.1, edge_color = ec, dpi=300)
    fig.suptitle("Modena_no_network_type")
    plt.show()
    ox.plot.save_and_show(fig, ax, save=True, show=False, close=True, filename = "Modena_no_network_type",
    file_format="png", dpi=300, axis_off=True)
    
    
    #--------PLOT GRAPH SPECIFYING THE NETWORK TYPE = WALK AND GET THE OSMIDs-------
    
    H = ox.graph_from_place(place, network_type = 'walk')
    
    osmid_network_walk = list([data['osmid'] for u, v, key, data in H.edges(keys=True, data=True)])
    
    ec = [one_way if data['oneway'] else two_way for u, v, key, data in H.edges(keys=True, data=True)]
    
    fig, ax = ox.plot_graph(H, bgcolor=background,
    show=False, close=True, fig_height=11, fig_width=11, node_size = 0, edge_linewidth = 0.1, edge_color = ec, dpi=300)
    fig.suptitle("Modena_network_walk")
    plt.show()
    ox.plot.save_and_show(fig, ax, save=True, show=False, close=True, filename = "Modena_network_walk",
    file_format="png", dpi=300, axis_off=True)
    
    #--------GET THE OSMIDs LIST OF MISSING EDGES AND PLOT MISSING EDGES IN MAGENTA---------
    
    missing_edges = [i for i in osmid_no_network + osmid_network_walk if i not in osmid_no_network or i not in osmid_network_walk]
    print(missing_edges)
    
    m_edges = (0.859, 0.180, 0.938, 1)
    ec2 = [m_edges if data['osmid'] in missing_edges else two_way for u, v, key, data in G.edges(keys=True, data=True)]
    
    fig, ax = ox.plot_graph(G, bgcolor=background,
    show=False, close=True, fig_height=11, fig_width=11, node_size = 0, edge_linewidth = 0.1, edge_color = ec2, dpi=300)
    fig.suptitle("Modena_missing_edges")
    plt.show()
    ox.plot.save_and_show(fig, ax, save=True, show=False, close=True, filename = "Modena_missing_edges", file_format="png", dpi=300, axis_off=True)
    

编辑:添加了Retain_all png Modena retain all true

编辑:将bbox area缩小到市中心并创建list of missing edges

1 个答案:

答案 0 :(得分:0)

您正在下载两种不同的网络类型:INPCKC:\OSGeo4W64\apps\Python27; C:\OSGeo4W64\apps\Python27\lib; C:\OSGeo4W64\bin; (这是默认设置),因此您将获得不同的网络。边缘似乎没有丢失,它们似乎是1)不可行走的边缘或2)断开的图形组件的一部分(因为您将PYTHONHOME = C:\OSGeo4W64\apps\Python27 PYTHONPATH = C:\OSGeo4W64\apps\Python27\lib GDAL_DRIVER_PATH = C:\OSGeo4W64\bin\gdalplugins 设置为其默认walk。 / p>