Hacker News new | past | comments | ask | show | jobs | submit login
Fast geodesic measurements in Go (github.com/jamesmilneruk)
64 points by mapsnapps on Aug 27, 2017 | hide | past | favorite | 10 comments



The usual way to do this is to convert latitude and longitude to ECEF (Earth centered, Earth fixed) coordinates.[1] This includes the corrections for the Earth being slightly pear-shaped. Then, given 3-element vectors for each point, compute the great circle distance between those points based on simple spherical geometry. This works everywhere, including at the poles.

The FCC formula is based on the old V and H coordinate system that the Bell System used for long distance in the electromechanical era. That was for North America.

There's tons of code out there for this, because every GPS device with a map has to do these calculations.

[1] https://www.mathworks.com/matlabcentral/fileexchange/7942-co...


The standard LLA to ECEF function uses the WGS84 reference ellipsioid, not pear shaped


It seems like that won't get the "fast": that code does 4 trigonometric functions and a sqrt while the OPs approximation seems to do one cached trig call and then one sqrt for each point.


Huh, why would that work?


Why is the distance function not implemented with Haversine's methods?

https://github.com/JamesMilnerUK/cheap-ruler-go/blob/master/...

Is there a reason to do this with looping?


The basic answer is speed and accuracy. The approximations implemented here are within 0.1% of the Vincenty method for distances under 500km, which is useful in all kinds of situations. The Haversine formula works for spheres, so it's not as accurate as the Vincenty method for the Earth (a flattened sphere), and it uses more trig functions than this approximation, so it's slower and less accurate for lon/lat distance calculations.

I work with Vlad (the author of the original Javascript https://github.com/mapbox/cheap-ruler). At the time it was created, we were basically just looking for the fastest method to get accurate distance calculations on lon/lat values within "short distances". Vlad found that this approximation fitted our needs well (i.e. the types of distances we typically needed to calculate distances for), and performed the best.

For really accurate measurements, you typically need to use a projection system that's targeted at the area you're measuring in. The earth isn't even a perfect flattened sphere, it's covered in lumps and bumps, so if you need really accurate measurements, you need to use one designed for the bump you're measuring on. Some great illustrations here: http://www.icsm.gov.au/mapping/datums1.html


Implementation of Helmert transformation in Go https://github.com/the42/cartconvert/blob/master/cartconvert...


Transverse Mercator with an accuracy of a few nanometers

https://link.springer.com/article/10.1007%2Fs00190-011-0445-...


It would be great if there were some usage examples in the readme or the godocs.


I'm looking into doing this at the moment. Also would like to add some benchmarks. I've added an example for distance measurement in the godocs and in the README.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: