4 ms·
Ellipsoid distance on Earth
- mirimir 8y agoThis is an easy-to-implement approach, with a great explanation.
- sorenjan 8y agoIf you're going to implement distance measuring it's probably better to use a package like GeoPy instead. https://geopy.readthedocs.io/en/stable/#module-geopy.distance https://geopy.readthedocs.io/en/stable/#module-geopy.distanc...
- pmiller2 8y agoFor a lot of use cases, the error in using the spherical approximation is small enough that it doesn’t matter. For instance, measuring distance between two points in the same city, you can happily use the shorter function and not worry about it.
- deleted 8y ago[deleted]
- thibautg 8y agoMost GIS applications have this functionality (distance on ellipsoid) built-it. For local distance measuring it is generally better and easier to use a projected coordinates system (where units are meters/miles instead of degrees). But if you are using a software without GIS functions (excel?) and only have a dataset with lat/long coordinates, then it is easier to use the short formula ;-)
- jabberthemutt 8y agoWhy does this use all the mathematical function from scipy instead of the built-in math? Are there significant benefits to that?
- snops 8y agoThey are actually from numpy, scipy just re-exports them, so they work with numpy arrays which the built in maths would not. I guess the author writes a lot of scientific code, so is in the habit of using them. Numpy arrays are much faster than python lists etc for maths and matrix operations, (e.g. multiply this 1000 element vector by 2), which are common in scientific and engineering code. https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.sin.html https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/...
- johndcook 8y agoYes, the author does write a lot of scientific code and is in the habit of using SciPy. -- the author :)
- jillesvangurp 8y agoThe alternatives are either using the pythagoras algorithm, which only makes sense for short distances (unless you are a flat earth believer) or the haversine algorithm: https://en.wikipedia.org/wiki/Haversine_formula https://en.wikipedia.org/wiki/Haversine_formula. Haversine is fine unless you really need super accurate results. The shorter the distance the less of an issue this is. If you are doing simple distance searches on a map with small radiuses, use whatever is good enough. I've used pythagoras for this in the past as part of a ranking formula as it is a lot cheaper to do that and it does not have to be super accurate.
- avs733 8y agoA funny example of this in practice happened a few years ago during the United Airlines and Continental Airlines merger. When they switched computer systems, somehow they switched the method they used to calculate the distances between cities for their frequent flyer program. Before the merger, both companies used the ellipsoid method. During the computer systems cutover, the method suddenly changed to a spherical approximation. They also used an incorrect The difference resulted in shorting flyers of a few (I think the most I saw was 40) frequent flyer miles per leg. They got caught within a couple days and 'fixed' the 'accidental' change. One of those things they seemed to hope no individual would catch but that over many many flyers would add up to a significant cost savings.