我是 osmnx、openstreatmap 和 nominatim 的新手。我正在尝试使用 in_degree_centrality networkx 函数检索具有最高/最大入度的节点。但是,extended_stats 字典中仅存在 degree_centrality 和 betweenness_centrality 。我如何找到这个节点?在我可以使用 Networkx 或 osmnx 中的 in_degree_centrality 函数之前,我是否必须将位置网络转换为有向图?
import osmnx as ox, networkx as nx, matplotlib.cm as cm, pandas as pd, numpy as np
place = 'City of Lethbridge, Alberta, Canada'
gdf = ox.gdf_from_place(place)
area = ox.project_gdf(gdf).unary_union.area
G = ox.graph_from_place(place, network_type='drive_service')
# calculate basic and extended network stats, merge them together, and display
stats = ox.basic_stats(G, area=area)
extended_stats = ox.extended_stats(G, ecc=True, bc=True, cc=True)
for key, value in extended_stats.items():
stats[key] = value
pd.Series(stats)
# unpack dicts into individiual keys:values
stats = ox.basic_stats(G, area=area)
for k, count in stats['streets_per_node_counts'].items():
stats['int_{}_count'.format(k)] = count
for k, proportion in stats['streets_per_node_proportion'].items():
stats['int_{}_prop'.format(k)] = proportion
# delete the no longer needed dict elements
del stats['streets_per_node_counts']
del stats['streets_per_node_proportion']
# load as a pandas dataframe
pd.DataFrame(pd.Series(stats)).T
G_projected = ox.project_graph(G)
max_node, max_bc = max(extended_stats['betweenness_centrality'].items(), key=lambda x: x[1])
print(max_node, max_bc)
nc = ['r' if node==max_node else '#336699' for node in G_projected.nodes()]
ns = [50 if node==max_node else 8 for node in G_projected.nodes()]
fig, ax = ox.plot_graph(G_projected, node_size=ns, node_color=nc, node_zorder=2)
G_projected = ox.project_graph(G)
in_degree= in_degree_centrality(G_projected) # computing the in_degree
max_node_deg, max_in_deg= max(in_degree['in_degree_centrality'])
具有最大入度的节点及其 NodeId 和经度和纬度。