本文介绍了osmnx经过一个路口的街道名称列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找osmnx产生的干净路口的街道信息.我看到我可以打印经/纬度信息,我还在Github上找到了一些答案,该答案是如何提取经过这些路口的街道名称.但是在某些情况下,它不会打印出通过该交叉路口的所有街道名称.我如何找到所有具有相应交叉路口的街道名称?我正在使用这里提到的这段代码[https://github.com/gboeing/osmnx/issues/199]

I am looking for street information for the clean intersections that are produced by osmnx. I see that I can print lat/lon information, I also found some answer on Github how to extract the street names going through those intersections. But in some cases, it doesn't print all street names going through that intersection.How can I find all street names with respective intersections?I am using this code mentioned here[https://github.com/gboeing/osmnx/issues/199]

我正在使用以下代码列出路口的街道名称.但是在某些路口,不会打印所有街道名称.那我该如何解决呢?@gboeing

I am using this following code to List street names for intersections. But in some intersections, all street names don't print. How can I then solve the case?@gboeing

import networkx as nx
import osmnx as ox
import geopandas as gpd
ox.config(log_console=True, use_cache=True)
G = ox.graph_from_place('Piedmont, California', network_type='drive')
G = ox.project_graph(G)
ints = ox.clean_intersections(G)
gdf = gpd.GeoDataFrame(ints, columns=['geometry'], crs=G.graph['crs'])
X = gdf['geometry'].map(lambda pt: pt.coords[0][0])
Y = gdf['geometry'].map(lambda pt: pt.coords[0][1])
nodes = ox.get_nearest_nodes(G, X, Y, method='kdtree')
connections = {}
for n in nodes:
connections[n] = set([])
for nbr in nx.neighbors(G, n):
    for d in G.get_edge_data(n, nbr).values():
        if 'name' in d:
            if type(d['name']) == str:
                connections[n].add(d['name'])
            elif type(d['name']) == list:
                for name in d['name']:
                    connections[n].add(name)
            else:
                connections[n].add(None)
        else:
            connections[n].add(None)
print(connections)

推荐答案

您没有提供代码示例,因此我猜测您在此处尝试执行的操作.但是,这是您如何用穿过交叉路口的所有街道名称(即,入射到您感兴趣的节点的边)来注释地块的方法:

You didn't provide a code example, so I'm guessing a bit at what you're trying to do here. But this is how you would annotate your plot with all the names of streets that go through an intersection (i.e., the edges incident to your node of interest):

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

# get graph within 200m of point
point = (37.821052, -122.230345)
G = ox.graph_from_point(point, dist=200, network_type='drive')

# consolidate intersections, make undirected graph, get edges GeoDataFrame
Gc = ox.consolidate_intersections(ox.project_graph(G), dead_ends=True)
edges = ox.graph_to_gdfs(ox.get_undirected(Gc), nodes=False)

# get edges incident to consolidated intersection of interest
node = ox.get_nearest_node(G, point)
incident_edges = edges[(edges['u_original']==node) | (edges['v_original']==node)]

# draw graph but do not show it yet
fig, ax = ox.plot_graph(Gc, bgcolor='k', edge_linewidth=5, edge_color='#666666',
                        node_size=0, show=False, close=False)

# annotate incident edges' names
for _, edge in incident_edges.fillna('').iterrows():
    text = edge['name']
    c = edge['geometry'].centroid
    ax.annotate(text, (c.x, c.y), c='w', fontsize=14)
plt.show()

另请参见 OSMNX网络图中的街道名称

这篇关于osmnx经过一个路口的街道名称列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-16 11:00