diff --git a/evrouting/osm/imports.py b/evrouting/osm/imports.py index 6eb3e3d7028d37681f9db609a334cde7a0d78bee..f08247fc4673e5482564ffafbf53564cc339a6c0 100644 --- a/evrouting/osm/imports.py +++ b/evrouting/osm/imports.py @@ -11,7 +11,6 @@ Added : - distance computation to estimate length of each ways (useful to compute the shortest path) """ - import copy import xml.sax import logging @@ -142,11 +141,11 @@ def read_osm(osm_xml_data, profile) -> OSMGraph: }) # Complete the used nodes' information - for n_id in G.nodes(): + for n_id, data in G.nodes(data=True): n = osm.nodes[n_id] - G.nodes[n_id]['lat'] = n.lat - G.nodes[n_id]['lon'] = n.lon - G.nodes[n_id]['id'] = n.id + data['lat'] = n.lat + data['lon'] = n.lon + data['id'] = n.id G.insert_into_rtree(n_id) return G diff --git a/evrouting/osm/routing.py b/evrouting/osm/routing.py index fe636d4ca8ff54cbc17f70bbfb48661a271daa26..0d9b110359fb39f20803c954087510505261505b 100644 --- a/evrouting/osm/routing.py +++ b/evrouting/osm/routing.py @@ -32,8 +32,6 @@ def haversine_distance(lon1, lat1, lon2, lat2, unit_m=True): def shortest_path(G, s: point, t: point, profile): """Calc A* shortest path.""" - _s = G.find_nearest(s) - _t = G.find_nearest(t) def dist(u, v): return haversine_distance( @@ -44,7 +42,7 @@ def shortest_path(G, s: point, t: point, profile): unit_m=True ) / profile['maxspeed'] * ms_to_kmh - return nx.astar_path(G, _s, _t, heuristic=dist) + return nx.astar_path(G, s, t, heuristic=dist) def to_coordinates(G, path):