您在图中具有每个节点和边的所有属性。您可以使用以下方法获取节点属性:
G.node[38862848]#out: {'highway': nan,# 'lat': 45.3210533,# 'lon': -122.9790558,# 'osmid': '38862848',# 'ref': nan,# 'x': 501641.47862882155,# 'y': 5018616.5723966481}G.node[38862848]['lat']# out: 45.3210533并获取边缘属性,您可以使用
G[u][v]:
G[5035130880][4963510289]# out: #{0: {'bridge': 'yes',# 'geometry': <shapely.geometry.linestring.LineString at 0x7f90ad7d5860>,# 'highway': 'secondary',# 'length': 671.332597496,# 'name': 'Northwest 185th Avenue',# 'oneway': False,# 'osmid': [124454683, 24446714, 124454682]}}所有属性也都在图形的GeoDataframe中。如果具有节点列表,则获取所有节点的几何形状的最简单方法是:
import osmnx as oximport networkx as nxgdf_nodes, gdf_edges = ox.graph_to_gdfs()path = nx.shortest_path(G, G.nodes()[0], G.nodes()[1])gdf_nodes.loc[path]#out: # highway lat lon osmid ref x y geometry traffic_signals#5035130880 NaN 45.5637 -122.868 5035130880 NaN 510334 5.04558e+06 POINT (510334.0390091945 5045583.999886028) 0#4963510289 NaN 45.5698 -122.868 4963510289 NaN 510329 5.04625e+06 POINT (510329.3114555664 5046254.728223645) 0# ...
输出是一个GeoDataframe。



