GeographicLib  1.41
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Implementations in other languages
Back to Code organization. Forward to Geoid height. Up to Contents.

Implementations of subsets of GeographicLib are available in other languages

C and Fortran implementation

The directories legacy/C and legacy/Fortran contain implementations of Geodesic, GeodesicLine, and PolygonAreaT in C and Fortran respectively. These are intended for use in old codes written in these languages and should work any reasonably modern compiler. These implementations are entirely self-contained and do not depend on the rest of GeographicLib. Sample main programs to solve the direct and inverse geodesic problems and to compute polygonal areas are provided.

For documentation, see

Java implementation

The directory java contains implementations of Geodesic, GeodesicLine, and PolygonAreaT in Java. This implementation is entirely self-contained and does not depend on the rest of GeographicLib. Sample main programs to solve the direct and inverse geodesic problems and to compute polygonal areas are provided.

For documentation, see

JavaScript implementation

The directory doc/scripts/GeographicLib contains the classes

translated into JavaScript. See Interface.js for a simple JavaScript interface to these routines (documented near the top of the file). Examples of using this interface are

These examples include a "stripped" version of the JavaScript code,

<script type="text/javascript"

which loads faster.

Python implementation

A python implementation of the geodesic routines from GeographicLib are provided in the python/geographiclib directory (which is installed as PREFIX/lib/python/site-packages/geographiclib, if COMMON_INSTALL_PATH is ON, and as PREFIX/python/geographiclib, otherwise). This contains implementations of the classes

You can also download the python interface independent of the rest of GeographicLib from

and then unpack the .tar.gz or .zip file.

You can "install" these routines, so that they are in python's default path with, for example

  cd geographiclib-1.16
  python install

(this will require root privileges). Or else you can set the path within python using

>>> import sys
>>> sys.path.append("/usr/local/lib/python/site-packages")

An example of using this interface is

>>> from geographiclib.geodesic import Geodesic
>>> # The geodesic inverse problem
... Geodesic.WGS84.Inverse(-41.32, 174.81, 40.96, -5.50)
>>> # The geodesic direct problem
... Geodesic.WGS84.Direct(40.6, -73.8, 45, 10000e3)
>>> # How to obtain several points along a geodesic
... line = Geodesic.WGS84.Line(40.6, -73.8, 45)
>>> line.Position( 5000e3)
>>> line.Position(10000e3)
>>> # Computing the area of a geodesic polygon
... def p(lat,lon): return {'lat': lat, 'lon': lon}
>>> Geodesic.WGS84.Area([p(0, 0), p(0, 90), p(90, 0)])
>>> # Introductory help
... help(Geodesic)

Another illustrative exercise is finding the point midway between JFK Airport to Singapore Changi Airport

from geographiclib.geodesic import Geodesic
# Coordinates of airports
lat1, lon1 = 40.640, -73.779 # JFK
lat2, lon2 = 1.359, 103.989 # SIN
# Compute path from 1 to 2
g = Geodesic.WGS84.Inverse(lat1, lon1, lat2, lon2)
# Compute midpoint starting at 1
h = Geodesic.WGS84.Direct(lat1, lon1, g['azi1'], g['s12']/2)
print(h['lat2'], h['lon2']);

(Note: The initial version of was provided by Andrew MacIntyre of the Australian Communications and Media Authority.)

Matlab and Octave implementations

The matlab directory Matlab and Octave implementations of some of the functions of GeographicLib. To use these, start Matlab or Octave and run one of (for example)

   addpath /usr/local/libexec/GeographicLib/matlab
   addpath 'C:/pkg-vc10-x64/GeographicLib-1.41/libexec/GeographicLib/matlab'

The functions fall into the following groups

There are two ways of compiling the interface code: (1) using cmake and (2) invoking the compiler from Matlab.

To use the interface routines for GeographicLib, run one of (for example)

  addpath /usr/local/libexec/GeographicLib/matlab
  addpath 'C:/pkg-vc10-x64/GeographicLib-1.41/libexec/GeographicLib/matlab'

in Octave or Matlab. The available functions are:

These routines just offer a simple interface to the corresponding C++ class. Use the help function to get documentation, e.g.,

help geodesicdirect

Unfortunately, the help function does not work for compiled functions in Octave; in this case, just list the .m file, e.g.,

type geodesicdirect

Other useful functions, e.g., to convert from geographic coordinates to MGRS can easily be written with Matlab code.

Note that geoidheight, when compiled with Visual Studio 2008 causes Matlab to crash. (The problem does not occur with Visual Studio 2005 or Visual Studio 2010.)

Maxima routines

Maxima is a free computer algebra system which can be downloaded from Maxima was used to generate the series used by TransverseMercator (tmseries.mac) and Geodesic (geod.mac) and to generate accurate data for testing (tm.mac and geodesic.mac). The latter uses Maxima's bigfloat arithmetic together with series extended to high order or solutions in terms of elliptic integrals (ellint.mac). These files contain brief instructions on how to use them.

.NET wrapper

This is a comprehensive wrapper library, written and maintained by Scott Heiman, which exposes all of the functionality of GeographicLib to the .NET family of languages. For documentation, see

Back to Code organization. Forward to Geoid height. Up to Contents.