File Exchange

image thumbnail


version (80.9 KB) by Charles Karney
MATLAB implementations of a subset of the C++ library, GeographicLib


Updated 05 Oct 2017

View License

GeographicLib toolbox
Version 1.49 2017-10-05
This toolbox provides native MATLAB implementations of a subset of the
C++ library, GeographicLib. Key components of this toolbox are
* Geodesics: direct, inverse, area calculations.
* Projections: transverse Mercator, polar stereographic, etc.
* Grid systems: UTM, UPS, MGRS.
* Geoid lookup: EGM84, EGM96, EGM2008 geoids supported.
* Geometric transformations: geocentric, local cartesian.
* Great ellipses: direct, inverse, area calculations.

There is some overlap between this toolbox and MATLAB's Mapping
Toolbox. However, this toolbox offers:

* better accuracy;
* treatment of oblate and prolate ellipsoids;
* guaranteed convergence for geoddistance;
* calculation of area and differential properties of geodesics;
* ellipsoidal versions of the equidistant azimuthal and gnomonic

Subsets of this package were previously released as:

Geodesics on an ellipsoid of revolution (deprecated)
Geodesic projections for an ellipsoid (withdrawn)
Great ellipses (withdrawn)

Including all of the functionality in a single toolbox allows easier
sharing of code (via a common private directory).

Extensive documentation on the C++ library is available at

Geoid lookup requires the installation of one or more geoid models.
Instructions for this are given in

A change log for this package is available at

Comments and Ratings (21)

Gunnar Zindel

Great Package!

help geocent_fwd says that lat and lon should be in degrees!
[X,Y,Z] = geocent_fwd(37.0328,15.065,370)
X = 4922883.48104775
Y = 1325070.28306503
Z = 3820522.46838327

To get the direction relative to one of the stations, you
should use loccart_fwd instead of geocent_fwd.


Good! Some discrepancies arise between this output coming from your drift
>> format long g
>> rad=pi/180;
>> lat=37.0328*rad;
>> lon=15.065*rad;
>> h=370.0;
>> [X,Y,Z]= geocent_fwd(lat,lon,h)
X = 6378036.70547581
Y = 29269.4077049027
Z = 71471.7403795619
and the following coming from with results been att'd previously [sendspace works properly, click twice instead] and copied below (1^st station only)
First Station : CB
X = 4922883.4811 m LAT = 37 1 58.08000 North
Y = 1325070.2831 m LON = 15 3 54.00000 East
Z = 3820522.4683 m EHT = 370.0000 Meters

The sendspace link seems to require that I create an account and provide an E-mail.
I'm not prepared to do this. So please figure out another way of sending me images.

If you want the Euclidean distance between 2 points you can just convert them to
geocentric coordinates with geocent_fwd and then use Pythagoras.


geoddistance enhancement proposal: mark-to-mark distance btw. two earth stations, like shown here:
Is it possible to do it and link here? Or, alternatively, to show (X,Y,Z) rectangular coords algorithm?
Thx in advance


Oh yes! It works properly now, the function becomes:
function n = GeodSolve59
% Check for points close with longitudes close to 180 deg apart.
n = 0;
[s12, azi1, azi2] = geoddistance(5, 0.00000000000001, 10, 180);
n = n + assertEquals(azi1, 0.000000000000035, 1.5e-14);
n = n + assertEquals(azi2, 179.99999999999996, 1.5e-14);
n = n + assertEquals(s12, 18345191.174332713, 5e-9);

@BlueEyes You are misinterpreting the patch file. The rule is remove the lines beginning
with "-" and replace them with the lines beginning with "+" (but with the "+" removed).
(Basically, the delta in the s12 test is changed from 2.5e-9 to 5e-9.)


Screenshot of the code amended


My GNU Octave 4.0.0 package still fails, as follows:
>> geographiclib_test
parse error near line 458 of file C:\Training\z_geodesia\karney\geographiclib_test.m

invalid left hand side of assignment

>>> - n = n + assertEquals(s12, 18345191.174332713, 2.5e-9);

This patch to geographiclib_test.m fixes the problem reported by BlueEyes (it relaxes
one of the tests slightly):

diff --git a/matlab/geographiclib/geographiclib_test.m b/matlab/geographiclib/geographiclib_test.m
index 2bad2f18..d301465e 100644
--- a/matlab/geographiclib/geographiclib_test.m
+++ b/matlab/geographiclib/geographiclib_test.m
@@ -457,7 +457,7 @@ function n = GeodSolve59
[s12, azi1, azi2] = geoddistance(5, 0.00000000000001, 10, 180);
n = n + assertEquals(azi1, 0.000000000000035, 1.5e-14);
n = n + assertEquals(azi2, 179.99999999999996, 1.5e-14);
- n = n + assertEquals(s12, 18345191.174332713, 2.5e-9);
+ n = n + assertEquals(s12, 18345191.174332713, 5e-9);

function n = GeodSolve61


Just sent the reply via email. Cheers

Reply to @BlueEyes: This may be a problem with the version of Matlab you
are used or the platform on which it is being run. Please could you run
the following in your version of Matlab (or Octave) to help me diagnose
the problem:

[s12, azi1, azi2] = geoddistance(5, 0.00000000000001, 10, 180);
fprintf('%.10f %.15f %.15f\n', s12, azi1, azi2)

and provide the results to me (E-mail is preferred: Thanks.


Please, be noticed of this drawback:
>> geographiclib_test
GeodSolve59 fail: 1
error: assert (n == 0) failed
error: called from
assert at line 92 column 11
geographiclib_test at line 56 column 3

2.. by eliminating the corresponding row, the test is successful:
% i = GeodSolve59; if i, n=n+1; fprintf('GeodSolve59 fail: %d\n', i); end
>> geographiclib_test


John (view profile)

Fantastic!! I have used geographiclib in Python and am very pleased it is now implemented in MATLAB.

Zhao Dejun

There's an obscure bug in geodreckon in calculating the area when an empty distance argument is given. A patch is provided in

This will be included in the next release.

Bill Tandy

Exactly what I was looking for! Thank you!


Guy (view profile)

The update to version 1.44 on 2015-08-14 caused a bug in geoddistance,
when it is used in Octave (not MATLAB) and is invoked with vector
arguments including nearly antipodal pairs of points on the equator.

A patch is given in

This will be included in the next release.


Chen Qiang



Update to version 1.49

Fix BUGS in geodreckon with mixed scalar and array arguments.
Default range for longitude and azimuth is (-180d, 180d].

Improve accuracy of area calculation (fixing a flaw introduced in version 1.46).
Fix vectorization of copysignx for MATLAB (Octave was already OK).

Improve the accuracy of the solution of the inverse problem when the
longitude difference is close to 180deg.

Synchronize with GeographicLib 1.45.
tranmerc_{fwd,inv} works with mixed scalar+array args.
couple of Octave-specific fixes.
array mismatch fix for geoddistance

Fix obscure bug in geoddistance (apply to Octave only).

Synchronize with GeographicLib 1.44.

Synchronize with GeographicLib 1.43.
Fix bug in the long_unroll feature of geodreckon.
mgrs_inv now takes an optional center argument.

Reverting to zip packaging. MATLAB Central produces a garbled zip file
when submitting a mltbx file.

Version 1.42.1 Repackage as a toolbox to eliminate spurious dependency. No change in .m files.

Sync with GeographicLib 1.42. Minor changes to documentation only.

Remove bogus dependency on Robust Control Toolbox (yet again!).

Remove bogus dependency on Robust Control Toolbox (again!).

Remove bogus required product.

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor