'Two nodes less than 1 mile apart on the same road fail to work in osmnx.shortest_path_length
I have successfully used osmnx.shortest_path_length to calculate many distances but these two nodes return : NetworkXNoPath: Node 9473072437 not reachable from 178685882.
The node locations were derived from ox.distance.nearest_nodes() and I have verified the the nodes in fact represent the locations I am trying to analyze using openstreetmaps: Node 1
As you can see they are quite close to each other. I have tried using simply the network of Sussex County, Delaware, as well as the entire state of Delaware. As expected this change had no impact.
g = ox.graph_from_place('Delaware, USA', network_type="drive")
dst = nx.shortest_path_length(g, source= 178685882, target= 9473072437, weight= 'length')
Solution 1:[1]
It's because the only way to access node 9473072437 is via service roads (namely this one), which you are not requesting with the "drive" filter. Use the "drive_service" filter to get all drivable roads including service roads:
import osmnx as ox
G = ox.graph_from_point((38.7776715, -75.3101692), dist=1500, network_type='drive_service')
path = ox.shortest_path(G, 178685882, 9473072437)
print(path)
path = ox.shortest_path(G, 9473072437, 178685882)
print(path)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | gboeing |