Creating isodistances using NetworkX (or OSMnx?)

235 views
Skip to first unread message

Dmitriy Tarasov

unread,
Nov 17, 2021, 10:57:10 AM11/17/21
to networkx-discuss
I need to find all roads within a certain distance from a certain point. Not the roads within a circle or box centered on the point, but distance as measured along the roads, in other words, isodistances. Is there a possibility of generating isodistances in NetworkX, or possibly in OSMnx? I remember reading somewhere in the documentation that OSMnx does provide the functionality for removing all nodes beyond a certain distance, which is similar to, but not quite, what I need. Thanks everyone for any advice on this.

seth....@gmail.com

unread,
Nov 17, 2021, 11:29:31 AM11/17/21
to networkx-discuss
Would something like single_source_dijkstra help here? The assumption here is the "point" here would be a node in the graph (i. e. intersection of roads in the OSMNx graph) and you could find all the other reachable nodes under a cutoff distance. If this needs to be an arbitrary point on the map, then maybe one way could be to find the nearest node first?

An example:

```
import networkx as nx
import osmnx as ox

distances, _ = nx.single_source_dijkstra(G, 53057697, weight='length', cutoff=1200)

# The following subgraph will give you all the other nodes in the graph which are reachable within the cutoff distance 1200
G.subgraph(distances.keys())

# Plot the subgraph to look at "isodistance" neighbourhood.
ox.plot_graph(G.subgraph(distances.keys()))
```

seth....@gmail.com

unread,
Nov 17, 2021, 11:31:19 AM11/17/21
to networkx-discuss
The graph G in the example is

G = ox.graph_from_place("Piedmont, California, USA", network_type="drive")


Dmitriy Tarasov

unread,
Nov 19, 2021, 9:37:23 AM11/19/21
to networkx-discuss
Thanks! Yes, I guess I would need to find the nearest node to my point first (and my point should be pretty close to a node). Is the cutoff distance in meters? Also, is there a way of adding new nodes to edges at a certain distance from my point, and using them as the cutoff points?
Reply all
Reply to author
Forward
0 new messages