tkrajina / gpxpy

gpx-py is a python GPX parser. GPX (GPS eXchange Format) is an XML based file format for GPS tracks.
Apache License 2.0
987 stars 223 forks source link

Correct distance between points with haversine formula #9

Closed xmw closed 11 years ago

xmw commented 11 years ago

Would be cool for larger distances between points.

Some kind of Coord1.dist_bearing(Coord2) would be nice.

http://www.movable-type.co.uk/scripts/latlong.html

tkrajina commented 11 years ago

Agree, I know this will become an issue sooner or later for somebody :) For me it isn't because I usually track my hikings or roadbike trails. But for bigger distances, this is needed.

I will implement it this week.

tk

PS. Thank for the link.

xmw commented 11 years ago

Hi,

I write an work paper in latex containing navigation points. My reference location is provided by an Garmin GPS45XL, downloaded to .gpx via gpsbabel. I use your module to parse this [1] and provide latex/siunitx representations and distance mesurements, like '\lat{A01} & \lon{A01} & \bear{A01}{MAH} & \dist{A01}{MAH}` as seen in figure [2].

I believe the formula in [1] are correct, the distance is the haversine formula, and the bearing is as referenced on the site (from wolfram-alpha ;-).

Maybe you just implement you version and we peer review the code later ;-)

Have a nice day!

Michael

[1] https://xmw.de/tmp/gpx_calc.py [2] https://xmw.de/tmp/tex_gpx.png [3] http://en.wikipedia.org/wiki/Haversine_formula

tkrajina commented 11 years ago

Hi Michael,

I implemented haversine here https://github.com/tkrajina/gpxpy/commit/a683cfa99af85c9daf526f8f6521181a3660011f (it is not yet merged in master, it is in haversine branch). I tested a little bit with the javascript implementation from your first link and the results seems OK to me (well, not exactly the same but I think this is because the floating point).

BTW. For GPX files I decided to keep the existing algorithm for points where latitudes or longitudes differ less than 0.5 because haversine have a lot more mathematical operations. I may change this treshold (or make it configurable).

Is it really that important to you? Because it seems to me that the difference for close points is very small (and your points are close enough).

If you can test it with your script and confirm it is OK to you -- I'll merge this to the master branch.

Cheers! tk