Find nearest geographic coordinates
Unix One
unix1@REDACTED
Fri Nov 27 18:24:43 CET 2020
Since I didn't see it mentioned in thread, I've previously used Haversine
formula [0] for this, and there's a sample implementation in Erlang [1]
(though I haven't personally validated this implementation).
Scaling this is interesting though, if needed. I stumbled upon an interesting
approach here [2].
[0] https://en.wikipedia.org/wiki/Haversine_formula
[1] https://rosettacode.org/wiki/Haversine_formula#Erlang
[2] https://mathamancer.wordpress.com/2016/06/26/discretizing-large-scale-haversine-calculations/
On Thursday, November 26, 2020 6:57:40 PM PST Richard O'Keefe wrote:
> When I had something similar to do, I found the simplest
> thing was to convert latitude and longitude to (x,y,z)
> points on the unit sphere. I then took advantage of the
> fact that great-circle distance on the surface of the
> sphere and chordal distance going through it are monotonically
> related, so the closest in 3-space is also the closest on the
> 2-sphere. See
> https://en.wikipedia.org/wiki/Great-circle_distance
>
> The obvious question is SCALE:
> how many points will there be?
> how many queries will there be?
> For my application, storing the 3d points in a k-d-tree
> with k=3 worked OK, but it was hundreds of points,
> not millions.
>
> On Thu, 26 Nov 2020 at 10:39, Frank Muller <frank.muller.erl@REDACTED>
>
> wrote:
> > Hi guys,
> >
> > I've a list of geographic coordinates:
> >
> > L = [ {{<<"longitude">>,6.1457}, {<<"latitude">>,46.2022}},
> >
> > {{<<"longitude">>,2.3387}, {<<"latitude">>,48.8582}},
> > ... ]
> >
> > and a specific coordinate X = {{<<"longitude">>,-73.5848},
> > {<<"latitude">>,45.4995}}.
> >
> > Question: how can i find the nearest coordinates to X from L (sorted from
> > the nearest to the farest)?
> >
> > /Frank
More information about the erlang-questions
mailing list