# OpenStreetMapX: How to efficiently convert node\_id to vertex\_id?

**URL:** https://discourse.julialang.org/t/openstreetmapx-how-to-efficiently-convert-node-id-to-vertex-id/98139
**Category:** Geo
**Tags:** question, for-loop, openstreetmapx
**Created:** [April 30, 2023, 7:04pm UTC](https://discourse.julialang.org/t/openstreetmapx-how-to-efficiently-convert-node-id-to-vertex-id/98139 "2023-04-30T19:04:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Yao\_Vang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yao_vang/32/49401_2.png) [@Yao\_Vang](https://discourse.julialang.org/u/Yao_Vang)
#### Post date: [April 30, 2023, 7:04pm UTC](https://discourse.julialang.org/t/openstreetmapx-how-to-efficiently-convert-node-id-to-vertex-id/98139/1 "2023-04-30T19:04:11Z")

</div>

Hello all

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

```julia
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

```julia
([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?

---

<div class="post-metadata">

### Author: ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)
#### Post date: [April 30, 2023, 10:22pm UTC](https://discourse.julialang.org/t/openstreetmapx-how-to-efficiently-convert-node-id-to-vertex-id/98139/2 "2023-04-30T22:22:26Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

### Author: ![Yao\_Vang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yao_vang/32/49401_2.png) [@Yao\_Vang](https://discourse.julialang.org/u/Yao_Vang)
#### Post date: [May 1, 2023, 9:05am UTC](https://discourse.julialang.org/t/openstreetmapx-how-to-efficiently-convert-node-id-to-vertex-id/98139/3 "2023-05-01T09:05:24Z")

</div>

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?

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

```

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](https://drive.google.com/file/d/1PX4sUJUab3_IacgO7xfNgRQBfxYtZQ5a/view?usp=share_link).
