2

I am comparing two different ways of calculating a distance between two Points.

  1. Haversine formula found on the page: http://www.movable-type.co.uk/scripts/latlong.html

  2. The following functionality of the geotools library:

GeodeticCalculator geodeticCalculator = new GeodeticCalculator(); geodeticCalculator.setStartingGeographicPoint(lng1, lat1); geodeticCalculator.setDestinationGeographicPoint(lng2, lat2); double distance = geodeticCalculator.getOrthodromicDistance();

The result for two coordinates in a range of about 100 meter differs by about 3 meters. And for longer distances (some 1000 km) even more (some kilometers). But it is also hard to check which one is more precise since you don't have a reference that you can really trust. (Don't know for example if google maps is that precise)

Any idea?

Subby
  • 1,997
  • 4
  • 22
  • 38
  • I answered a similar question recently, Haversine vs geography type in SQL Server spatial, see: http://stackoverflow.com/questions/25422857/differences-in-distance-calculated-between-javascript-function-and-sql-server-st/25432042#25432042. Your assumptions about the earth's shape are correct. – John Powell Sep 02 '14 at 12:50

2 Answers2

3

Just to answer my own question after some more research:

Geotools library is more precise here, since it uses the WGS84 Model by default if instantiated with an empty constructor.

The other formula uses an inacurate spherical model of the earth.

Subby
  • 1,997
  • 4
  • 22
  • 38
2

I'm no expert, but the docs on the Haversine formula say that it assumes a spherical earth. Whereas the earth is acutally a geoid shape. And so I'd assume the GeodeticCalculator to be more accurate.

If you want more detal better to ask in the GIS stack exchange.

David Roussel
  • 5,788
  • 1
  • 30
  • 35