OpenStreetMapX: How to efficiently convert node_id to vertex_id?

Yao_Vang
Sun, 30 Apr 2023 19:04:11 +0000
Geo

Hello all

When calling any routing opetion in openstreetmapX it expects node_id and in the answer it also returns node_id. for example:

m = get_map_data(File_path, use_cache=false, trim_to_connected_graph=true );
a,b = [point_to_nodes(generate_point_in_bounds(m), m) for _ in 1:2]

path= shortest_route(m,  a,b)

will return

([42450876, 9545963078, 9907942869, 9181587079, 42423051, 370894399, 8874226523, 370894980, 370897166, 370898177  …  103295503, 103268226, 103134583, 103134579, 440215474, 103139598, 103139589, 103139570, 103139525, 103168154], 26093.74290233146, 1113.1120485313381)

Where 42450876 are node_ids .
Now calling m.v[42450876] gives 323 which is the vertex_id (label) associated to node_id 42450876 of the m.g Graph. object.

I want to convert all these node_ids to their vertex_ids. In other wordes, when calling shortest_route how to get vertices rather than node_ids? Or how to get coordinates?

The only way I can think of is to loop over all node_ids whithin a path and then call m.v on it. But is this efficint for a map contaning lots of nodes and when you nedd to process more than 1 paths?

3 posts - 2 participants