diff --git a/evrouting/osm/routing.py b/evrouting/osm/routing.py index acbe5844f34508efe459d83b44db00ec6e8b97ed..e030986328b6f2005e45dda0234698e52d931845 100644 --- a/evrouting/osm/routing.py +++ b/evrouting/osm/routing.py @@ -66,3 +66,18 @@ def shortest_path(G, s: point, t: point, profile): ) / profile['maxspeed'] * ms_to_kmh return nx.astar_path(G, _s, _t, heuristic=dist) + + +def to_coordinates(G, path): + """ + Path of nodes to path of coordinates. + + Note: Coordinates are (lon, lat) to conform to + geojson. + """ + def get_coordinates(n): + lat = G.nodes[n]['lat'] + lon = G.nodes[n]['lon'] + return lon, lat + + return list(map(get_coordinates, path)) diff --git a/tests/osm/test_osm_charge.py b/tests/osm/test_osm_charge.py index fffd31684b2138c43eb39528a369ecc0f07a9bd3..5a2bbb0161d305c87bd5871b16f99d0751fa7b6f 100644 --- a/tests/osm/test_osm_charge.py +++ b/tests/osm/test_osm_charge.py @@ -73,3 +73,20 @@ def test_shortest_route(map_graph): ] assert route == shortest_path(map_graph, s, t, car) + + +def test_other_shortest_route(map_graph): + s = (51.75344308292687, 6.943187713623048) + t = (51.754452602619935, 6.958980560302735) + + route = [ + "1827268706", + "1826594887", + "4955446046", + "4955446048", + "34053450", + "4955446051", + "418009799" + ] + + assert route == shortest_path(map_graph, s, t, car)