Search code examples
nodesosmnx

Applying weightings to nodes/intersections in OSMNX


I've been searching for a way to apply weightings to the nodes/intersections themselves on OSMNX as opposed to the edges. Anyone know or figured out if the package allows for nodes to be given weightings?


Solution

  • Similar to the answer by Debjit Bhowmick, you could do this more efficiently directly with Networkx:

    import networkx as nx
    import osmnx as ox
    G = ox.graph_from_place('Piedmont, CA, USA', network_type='drive')
    
    # create node weights
    w = {k: 3 if v == 'turning_circle' else 1 for k, v in G.nodes(data='highway')}
    nx.set_node_attributes(G, w, 'weight')