GeographicLib  1.45
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.

This package is available on Maven Central; so if you're using Apache Maven as your build system, you can use this package by including the dependency

  <dependency>
<groupId>net.sf.geographiclib</groupId>
<artifactId>GeographicLib-Java</artifactId>
<version>1.45</version>
</dependency>

in your pom.xml.

For documentation, see

# JavaScript implementation

The directory js/src contains the classes

translated into JavaScript. When GeographicLib is built the JavaScript source files are concatenated and compressed into a single file geographiclib.min.js. This can be included into your document with

<script type="text/javascript"
src="http://geographiclib.sf.net/scripts/geographiclib.min.js">
</script>

This file gives you the latest version of the library. If you need to use a specific version of this file, include a version number as in

<script type="text/javascript"
src="http://geographiclib.sf.net/scripts/geographiclib-1.45.min.js">
</script>

You can visit http://geographiclib.sf.net/scripts/ to see which versions are available.

Starting with version 1.45, this package is available as an node package that can be installed with npm (thanks to Yurij Mikhalevich for help with this work). To install this as a node package, use

  npm install geographiclib

For documentation, see

Examples of using this interface are

• a geodesic calculator showing the solution of direct and inverse geodesic problem, finding intermediate points on a geodesic line, and computing the area of a geodesic polygon.
• displaying geodesics in Google Maps which shows the geodesic, the geodesic circle, and various geodesic envelopes.

# 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 install the Python interface independent of the rest of GeographicLib using pip

  pip install geographiclib

This requires root privileges and you might first need to install the python-pip package.

and 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 setup.py install


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

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

An example of using this interface is

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

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

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

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

# MATLAB and Octave implementations

The matlab/geographiclib directory contains 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/share/matlab/geographiclib
addpath C:/pkg-vc10-x64/GeographicLib-1.45/matlab/geographiclib

A summary of the routines is obtained by

   help geographiclib

These MATLAB functions is also available from the MATLAB File Exchange site as the GeographicLib toolbox, package 50605.

The functions fall into the following groups

• Geodesics
• geoddistance - Distance between points on an ellipsoid
• geodreckon - Point at specified azimuth, range on an ellipsoid
• geodarea - Surface area of polygon on an ellipsoid
• Projections
• tranmerc_fwd - Forward transverse Mercator projection
• tranmerc_inv - Inverse transverse Mercator projection
• polarst_fwd - Forward polar stereographic projection
• polarst_inv - Inverse polar stereographic projection
• eqdazim_fwd - Forward azimuthal equidistant projection
• eqdazim_inv - Inverse azimuthal equidistant projection
• cassini_fwd - Forward Cassini-Soldner projection
• cassini_inv - Inverse Cassini-Soldner projection
• gnomonic_fwd - Forward ellipsoidal gnomonic projection
• gnomonic_inv - Inverse ellipsoidal gnomonic projection
• Grid systems
• utmups_fwd - Convert to UTM/UPS system
• utmups_inv - Convert from UTM/UPS system
• mgrs_fwd - Convert UTM/UPS coordinates to MGRS
• mgrs_inv - Convert MGRS to UTM/UPS coordinates
• Geoid lookup
• geoid_height - Compute the height of the geoid
• Great ellipses
• gedistance - Great ellipse distance between points on an ellipsoid
• gereckon - Point along great ellipse at specified azimuth and range
• Geometric transformations
• geocent_fwd - Conversion from geographic to geocentric coordinates
• geocent_inv - Conversion from geocentric to geographic coordinates
• loccart_fwd - Convert geographic to local cartesian coordinates
• loccart_inv - Convert local cartesian to geographic coordinates
• Utility
• defaultellipsoid - Return the WGS84 ellipsoid
• ecc2flat - Convert eccentricity to flattening
• flat2ecc - Convert flattening to eccentricity
• Documentation
• geoddoc - Geodesics on an ellipsoid of revolution
• projdoc - Geodesic projections for an ellipsoid
• gedoc - Great ellipses on an ellipsoid of revolution

These functions reimplement the C++ routines from GeographicLib in MATLAB code (but note that routines for great ellipses are only available as MATLAB code). Because these functions are all vectorized, their performance is comparable to the C++ routines. The minimum version numbers required are

• MATLAB, version 7.9, 2009b,
• Octave, version 3.4, Feb. 2011.

In addition, in order to use the geoid routines, Octave needs to have been built with a version of GraphicsMagick which supports 16-bit images.

Previously, some of these routines were packaged as three separate packages

These packages have now all been incorporated into the GeographicLib toolbox.

Prior to version 1.42, GeographicLib was distributed with some MATLAB functionality offered via compiled interface code. This has now been replaced by native MATLAB wrapper functions which call the functions in the GeographicLib toolbox. To use these wrapper functions, run one of:

   addpath /usr/local/share/matlab/geographiclib-legacy
addpath C:/pkg-vc10-x64/GeographicLib-1.45/matlab/geographiclib-legacy

The GeographicLib toolbox must also be in your MATLAB path. A summary of the routines is obtained by

   help geographiclib-legacy

These functions are DEPRECATED. Here is a function listing

• Geodesics
• geodesicdirect - Wrapper for geodreckon
• geodesicinverse - Wrapper for geoddistance
• geodesicline - Another wrapper for geodreckon
• polygonarea - Wrapper for geodarea
• Grid systems
• utmupsforward - Wrapper for utmups_fwd
• utmupsreverse - Wrapper for utmups_inv
• mgrsforward - Wrapper for mgrs_fwd
• mgrsreverse - Wrapper for mgrs_inv
• Geoid lookup
• geoidheight - Wrapper for geoid_height
• Geometric transformations
• geocentricforward - Wrapper for geocent_fwd
• geocentricreverse - Wrapper for geocent_inv
• localcartesianforward - Wrapper for loccart_fwd
• localcartesianreverse - Wrapper for loccart_inv
• Deprecated
• geographiclibinterface - Compile interface code (DEPRECATED)

The last routine can be used to compile the obsolete interface code (which is still provided as C++ code in the same directory). Doing this will switch MATLAB from using the native MATLAB routines to the compiled interface. However, the native code is easier to deploy and is about as fast; so the compiled interface will be removed at some point in 2016.

# Maxima routines

Maxima is a free computer algebra system which can be downloaded from http://maxima.sf.net. Maxima was used to generate the series used by TransverseMercator (tmseries.mac), Geodesic (geod.mac), Rhumb (rhumbarea.mac), The area under a great ellipse (gearea.mac), the relation between Auxiliary latitudes (auxlat.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.