OSMNX网络图中的街道名称 [英] Street names in OSMNX network maps

查看:64
本文介绍了OSMNX网络图中的街道名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在osmnx上构建街道网络.我看到我可以打印纬度/经度信息,但是

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)

输出:

推荐答案

以下是使用OSMnx注释地图以显示街道/道路名称(或图中任何其他边线属性)的方法.相同的逻辑将应用于标记节点.

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.

这篇关于OSMNX网络图中的街道名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆