Reduce openstreetmap graph size in networkx -


i have graph (transformed osmnx) of london's walk path, containing 667.588 edges, different highway attributes (the street types in openstreetmap). running shortest_path algorithm quite slow (4 seconds). improve speed, want largely reduce number of edges in systematic way without losing main connections/city structures, not sure how it? suggestions? there way group close nodes more important one, reduce size?

you can extract edges desired highway types main graph g:

highways_to_keep = ['motorway', 'trunk', 'primary'] h = nx.multidigraph() u,v,attr in g.edges(data=true):     if attr['highway'] in highways_to_keep:         h.add_edge(u,v,attr_dict=attr)         h.node[u] = g.node[u]         h.node[v] = g.node[v] 

here, first initialized empty multidigraph, type of graph used osmnx, populate data main graph g, if 'highway' attribute in our list of highways_to_keep. can find more highway types in this openstreetmap page.

our graph valid networkx graph, need 1 more thing before can take advantage of osmnx functionalities well. if execute g.graph, see graph attributes contains crs (coordinate reference system) , other things. should add information newly create graph:

h.graph = g.graph 

here plot of h , osmnx.plot_graph(h):

enter image description here


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -