Opened 4 years ago

Last modified 4 years ago

#3426 new feature

Accurate treatment of geodesics

Reported by: karney Owned by:
Priority: minor Milestone: 2.13 Release
Component: Util Version: 2.10
Keywords: Geodesics Cc:


OpenLayers 2.10 provides distVincenty and destinationVincenty which compute geodesics using Vincenty's method. However this method suffers from two problems:

  • the distance calculation fails to converge from some pairs of points;
  • where it converges the error is rather large (about 0.5mm).

OpenLayers also provides a function getGeodesicArea which is inaptly named because

  • it treats only a sphere and not the ellipsoid;
  • the edges of the polygon are not geodesics (or great circles) but rather straight lines on a cylindrical equal-area projection;
  • the polygon cannot enclose a pole.

The attached patch adds distGeodesic, destinationGeodesic, and getTrueGeodesicArea which correct the problems noted about. These use the Javascript port of the geodesic functionality in GeographicLib. For a sample of the capabilities, see

GeographicLib also provides facilities which may be useful to OpenLayers in the future (for instance it can simplify finding the intersection of geodesics).

GeographicLib using the MIT/X11 license so you are free to incorporate it into OpenLayers.

Attachments (1)

openlayers-2.10.patch (4.8 KB) - added by karney 4 years ago.

Download all attachments as: .zip

Change History (3)

Changed 4 years ago by karney

comment:1 Changed 4 years ago by ahocevar

Thanks @karney for the pointer to GeographicLib and this great contribution. Unfortunately I didn't have much time to review, so just a quick comment:

One thing that comes to mind would be that instead of adding a new getTrueGeodesicArea method, it would make sense to check for the availability of GeograpicLib, use it if available, and otherwise fall back to Vincenty. Maybe this mechanism could be implemented without adding Util.distGeodesic and Util.destinationGeodesic methods. I'm saying this because we don't want to increase the size of Util.js unless inevitably needed.

comment:2 Changed 4 years ago by karney

A possibility would be to distribute the GeographicLib js files with OpenLayers and then dump {dist,destination}Vincenty in favor of {dist,destination}Geodesic. This would allow you to shrink Util.js.

Note: See TracTickets for help on using tickets.