# Good Julia function / algorithm idea to find the nearest node to a given point location based on some given road network (for example, open street map data)?

**URL:** <https://discourse.julialang.org/t/good-julia-function-algorithm-idea-to-find-the-nearest-node-to-a-given-point-location-based-on-some-given-road-network-for-example-open-street-map-data/22787>\
**Category:** Performance\
**Created:** [April 5, 2019, 9:12am UTC](https://discourse.julialang.org/t/good-julia-function-algorithm-idea-to-find-the-nearest-node-to-a-given-point-location-based-on-some-given-road-network-for-example-open-street-map-data/22787 "2019-04-05T09:12:49Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [October 12, 2022, 3:13pm UTC](https://discourse.julialang.org/t/good-julia-function-algorithm-idea-to-find-the-nearest-node-to-a-given-point-location-based-on-some-given-road-network-for-example-open-street-map-data/22787/5 "2022-10-12T15:13:22Z")

</div>

Hi @pszufe, I have around 8M coordinates I’d like to associate with nearest node on an OpenStreetMapX with around 800,000 nodes, but I’m finding it hard to compute even 10,000 points. Here is a graph of benchmarks

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/2/1221e5f91aee038d4f43902c47c92eb7b96ed134.png)

computed like this:  
`b4 = @benchmark [point_to_nodes(pt, mad) for pt in ptsOrig] setup=(ptsOrig = zip($(df.dLat[1:10_000]), $(df.dlng[1:10_000])))`

Is there a quick way around this? if spatial indexing is the only solution, there’s a native Julia option here [GitHub - alyst/SpatialIndexing.jl: Spatial data indexing in pure Julia (R\*-trees etc)](https://github.com/alyst/SpatialIndexing.jl) and others listed here [https://juliageo.org/](https://juliageo.org/)

Do you recommend any one in particular nowadays and is there a quick tutorial somewhere as to how to build the index given an OpenStreetMap and any of these libraries?

Thanks in advance.

---

_[View the full topic](https://discourse.julialang.org/t/good-julia-function-algorithm-idea-to-find-the-nearest-node-to-a-given-point-location-based-on-some-given-road-network-for-example-open-street-map-data/22787)._
