Check which edge attributes exist (NetworkX)

2019-08-10 06:14发布

问题:

I'm using OSMNX to load an OpenStreetMap file of a city into NetworkX. Is there any way for me to see which attributes are stored in the graph? I believe OSMNX might for instance store the length of a street, or the type of road. I want to know what the names of the attributes are that I can access.

回答1:

You could either display the edges to see what's in them:

import osmnx as ox
G = ox.graph_from_place('Piedmont, California', network_type='drive')
print(G.edges(keys=True, data=True))

Or you could use OSMnx to convert the edges to a GeoDataFrame and inspect its columns:

edge_attributes = ox.graph_to_gdfs(G, nodes=False).columns
print(edge_attributes)