问题
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