The output of the following code
import osmnx as ox
import networkx as nx
import folium
G = ox.graph_from_place('Wuppertal, Germany', network_type='drive')
G = ox.speed.add_edge_speeds(G)
G = ox.speed.add_edge_travel_times(G)
orig = ox.get_nearest_node(G, (51.262336765,7.143472955))
print(orig)
dest = ox.get_nearest_node(G, (51.2521799,7.1491453))
print(dest)
orig = ox.nearest_nodes(G, X=51.262336765, Y=7.143472955)
print(orig)
dest = ox.nearest_nodes(G, X=51.2521799, Y=7.1491453)
print(dest)
is
279086833
269525495
317558105
317558105
Why does nearest_node
return a result different from get_nearest_node
? In particular, I have a problem with this, because when I plot the shortest route between orig
and dest
using get_nearest_node
using the following code
route_map = ox.plot_route_folium(G, route)
route_map.save('test_1.html')
everything works fine. When I try to do the same using nearest_nodes
I get the error
Traceback (most recent call last):
File "/Users/danielagaul/sciebo/PycharmProjects/distances/test_osm.py", line 20, in <module>
route_map = ox.plot_route_folium(G, route)
File "/Users/danielagaul/opt/anaconda3/envs/osm_new/lib/python3.8/site-packages/osmnx/folium.py", line 137, in plot_route_folium
gdf_edges = utils_graph.graph_to_gdfs(G.subgraph(route), nodes=False).loc[uvk]
File "/Users/danielagaul/opt/anaconda3/envs/osm_new/lib/python3.8/site-packages/osmnx/utils_graph.py", line 65, in graph_to_gdfs
raise ValueError("graph contains no edges")
ValueError: graph contains no edges
How can I get the old results using the new function?