4

I am fairly new to this geo distance. My use case is to find short distances as a person walks. So I will have 2 sets of (lat,lon)s. Now to find the distance I could use Euclidean distance easily. Looks like the distance conversion will be like this:

6371000. * Sqrt[dx^2 + dy^2]] * pi / 180 meters

So I wrote a simple code to find out the comparison:

import math
from haversine import haversine
test = [
[lat,lon,lat,lon],
...
[lat,lon,lat,lon]
]

for x in test:
  dist = math.hypot(x[2] - x[0], x[3] - x[1]) * 6371000*math.pi/180
  hv = haversine(x[0:2],x[2:4])*1000
  print('eucledian: %0.3f' %  dist, '\thaversine: %0.3f ' % hv, '\toffset: %0.3f' % (hv - dist),'m')

My Results looked like this:

eucledian: 0.127    haversine: 0.111    offset: -0.015 m
eucledian: 0.273    haversine: 0.219    offset: -0.053 m
eucledian: 1.875    haversine: 1.715    offset: -0.159 m
eucledian: 2.460    haversine: 2.387    offset: -0.073 m
eucledian: 0.961    haversine: 0.881    offset: -0.080 m
eucledian: 0.099    haversine: 0.084    offset: -0.016 m

So the question is which one is accurate and what causes the difference? What is the most accurate distance formula to be used? The distance in my case is less than a meter.

user 923227
  • 141
  • 1
  • 5
  • I haven't looked at your code in detail, but keep in mind that haversine gives you great-circle distance (along the surface of the Earth), whereas the Euclidean metric gives you straight-line distance (through the Earth). That may account for the discrepancy. – Brian Tung Oct 30 '18 at 19:39
  • But the great-circle (as the crow flies) distance will always be greater than the Euclidean (as the worm digs) distance. – Lubin Oct 30 '18 at 20:54
  • Then in this case using the euclidean distance formula is more accurate as the distance is a straight line distance around one meter at most. – user 923227 Oct 30 '18 at 22:12
  • @user923227: Wha-ah? The error should not be so large on that small a distance. I'd be more concerned about roundoff errors. If I get a chance, I'll take a closer look at this. What are your test lat/lons? – Brian Tung Oct 30 '18 at 22:53
  • 1
    I don't know what you're pushing into this, but you can't use hypot that way. Degrees (and subparts of degrees) are different in longitude and latitude, except right at the equator, because degrees of longitude shrink as you get closer to the poles, and degrees of latitude don't. You need to convert first to rectangular coordinates (in meters), then apply hypot to the difference in x, y, and z coordinates. But are you sure you're meant to be expressing the endpoints of a distance of a few meters in longitude and latitude?! – Brian Tung Oct 30 '18 at 23:05
  • Hi @BrianTung, I looked at the url pasted above: "The distance conversion will be like this: https://stackoverflow.com/questions/45842996/what-is-the-unit-of-measurement-for-distance-of-esri-function-st-distance-return/52979177#52979177" – user 923227 Oct 31 '18 at 00:50
  • 1
    @user923227: I read that. But this is not valid for longitude and latitude, because those degrees are not equal in general. It works for the Cartesian plane. – Brian Tung Oct 31 '18 at 01:57
  • @BrianTung - What do you mean when you say - longitude latitude degrees are not equal in general? – user 923227 Nov 07 '18 at 01:28
  • @user923227: For instance, at a latitude of 40 degrees, each degree of longitude is about 53 statute miles, and at a latitude of 70 degrees, each degree of longitude is about 24 statute miles. But a degree of latitude is always about 69 statute miles (there's some minor variation because the Earth is not a perfect sphere). Why this is true should be evident if you look at a globe: The lines of longitude are maximally far apart at the equator, and converge at the poles. – Brian Tung Nov 07 '18 at 02:47
  • @BrianTung Thanks for explaining. In my case the distance is in the order of meters. My lat. lon values have 7 decimal places. Then Haversine distance formula should be used or is there any other formula to be considered? – user 923227 Nov 07 '18 at 03:48
  • https://gis.stackexchange.com/questions/58653/what-is-approximate-error-of-pythagorean-theorem-vs-haversine-formula-in-measur#:~:text=Using%20the%20Pythagorean%20formula%20on,suppose%20it%20ought%20to%20work.&text=Distances%20along%20lines%20of%20longitude%20will%20be%20reasonably%20accurate. – Scb Oct 25 '23 at 12:22

1 Answers1

1

The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes.

Using the Pythagorean formula on positions given in latitude and longitude makes as little sense as, say, computing the area of a circle using the formula for a square: although it produces a number, there is no reason to suppose it ought to work.

Most often people answer "no, the Pythagorean theorem only works on a 2D Euclidean plane." Rarely, however, do people mention the effect of scale and location on the sphere on how inaccurate the Pythagorean theorem is.

The basic idea being at very small scales, the surface of a sphere looks very much like a plane. At very large scales, it distances along the surface are more curved and therefore the difference between the incorrect Pythagorean Theorem and the correct Haversine Formula is greater.

  • https://gis.stackexchange.com/questions/58653/what-is-approximate-error-of-pythagorean-theorem-vs-haversine-formula-in-measur#:~:text=Using%20the%20Pythagorean%20formula%20on,suppose%20it%20ought%20to%20work.&text=Distances%20along%20lines%20of%20longitude%20will%20be%20reasonably%20accurate. – Scb Oct 25 '23 at 12:21