Search code examples
pythonopenstreetmapnetworkx

Check which edge attributes exist (NetworkX)


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.


Solution

  • 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)
    

    Finally, note that you can configure which OSM attributes OSMnx attaches to graph nodes and edges by passing the useful_tags_way or useful_tags_node arguments to ox.config().