OSMnx находит кратчайший путь ориентированного графа с помощью networkx - PullRequest
0 голосов
/ 28 апреля 2020

В OSMnx улицы направлены, чтобы сохранить однонаправленную направленность, и поэтому, когда я пытаюсь найти кратчайший путь, используя Networkx, я получаю NetworkXNoPath: нет пути к (osmid) . Как мне исправить эту проблему? Мне нужно найти кратчайший путь в сети с улицами с односторонним движением.

См. Код ниже:

import osmnx as ox

import networkx as nx
# define place
centreLat=40.771687
centreLon=-73.957233

# download osm data

G= ox.graph_from_point((centreLat,centreLon), distance=1000, network_type='drive',simplify = True)  

# plot the graph
fig,ax = ox.plot_graph(G)

# Get origin x and y coordinates
orig_xy = 40.7647425, -73.9683181

# Get target x and y coordinates
target_xy =40.7804348, -73.9498809

# Find the node in the graph that is closest to the origin point (here, we want to get the node id)
orig_node = ox.get_nearest_node(G, orig_xy, method='euclidean')


# Find the node in the graph that is closest to the target point (here, we want to get the node id)
target_node = ox.get_nearest_node(G, target_xy, method='euclidean')

# Get shortest path 
route = nx.shortest_path(G, source=orig_node, target=target_node, weight='length')

# Plot the shortest path
fig, ax = ox.plot_graph_route(G, route, origin_point=orig_xy, destination_point=target_xy)

1 Ответ

0 голосов
/ 01 мая 2020

Эта проблема была исправлена ​​путем создания сильно связанных компонентов ориентированного графа, чтобы гарантировать, что каждая вершина доступна из любой другой вершины.

G=ox.geo_utils.get_largest_component(G,strongly=True)
...