OpenStreetMapX: How to efficiently convert node_id to vertex_id?

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?

Using getindex and broadcasting allows to cleanly apply the method of conversion you suggested to all points:

getindex.(m.v, path[1])

P.S. When adding code in a post, it is really nice for readers to be able to run it with copy-paste, i.e. supply some way to access a toy File_path file.

1 Like

Thanks @Dan . I’ll give it a try. I was hoping to find a builtin function inside osmx itself. There are some covert options but whatever I tired it returns incompatible type.

So, for k path I need to wrap getindex.(m.v, path[i]) into a for loop, right?

for i in 1:length(paths)
     verticies = getindex.(m.v, path[i])

Yes, I wanted to attach a simple file as a file path but as its *.osm, I was unable to do so. Sorry about that. This is a very small map.