Case Msee
Case Msee

Reputation: 405

Street names in OSMNX network maps

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

Output:

enter image description here

Upvotes: 1

Views: 2337

Answers (1)

gboeing
gboeing

Reputation: 6442

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()

enter image description here

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

Upvotes: 5

Related Questions