Street names in OSMNX network maps

守給你的承諾、 提交于 2021-01-28 08:45:20

问题


I am constructing street networks on osmnx using below code.I see that I can print lat/lon information, but

  • Is there a way to include street/road names in network maps as well? I don't see how to do this in the documentation. Thanks!

    import osmnx as ox
    G = ox.graph_from_bbox(37.79, 37.78, -122.41, -122.43, network_type='drive')
    G_projected = ox.project_graph(G)
    ox.plot_graph(G_projected)
    

Output:


回答1:


Here's how you annotate your map with OSMnx to show street/road names (or any other edge attributes in the plot). The same logic would apply to labeling nodes instead.

import matplotlib.pyplot as plt
import osmnx as ox
ox.config(use_cache=True, log_console=True)

G = ox.graph_from_address('Piedmont, CA, USA', dist=200, network_type='drive')
G = ox.get_undirected(G)

fig, ax = ox.plot_graph(G, bgcolor='k', edge_linewidth=3, node_size=0,
                        show=False, close=False)
for _, edge in ox.graph_to_gdfs(G, nodes=False).fillna('').iterrows():
    c = edge['geometry'].centroid
    text = edge['name']
    ax.annotate(text, (c.x, c.y), c='w')
plt.show()

The only aesthetic challenge being the label placement problem, which is one of the most difficult problems in computational cartography.



来源:https://stackoverflow.com/questions/60886350/street-names-in-osmnx-network-maps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!