GeographicLib
1.21
|
Interfaces to subsets of GeographicLib are available in other languages
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" src="http://geographiclib.sf.net/scripts/geographiclib.js"> </script>
which loads faster.
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). 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 setup.py 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)
(Note: The initial version of setup.py was provided by Andrew MacIntyre of the Australian Communications and Media Authority.)
The matlab directory contains interface code so that some GeographicLib classes can be accessed from Matlab or Octave. There are two ways of compiling this code: (1) using cmake and (2) invoking the compiler from Matlab.
mex.bat -setup Please choose your compiler for building external interface (MEX) files: Would you like mex to locate installed compilers [y]/n? y Select a compiler: [1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2010b\sys\lcc [2] Microsoft Visual C++ 2010 in C:\Program Files\Microsoft Visual Studio 10.0 [0] None Compiler: 2 etc.
mex -setup
.) Then configure cmake with, for example cmake -G "Visual Studio 10" -D MATLAB_COMPILER=mex ..
cmake -D MATLAB_COMPILER=mkoctfile ..
mex -setup cd 'C:/pkg-vc10-x64/GeographicLib-1.21/libexec/GeographicLib/matlab' help geographiclibinterface geographiclibinterface('C:/pkg-vc10/GeographicLib-1.21'); addpath(pwd);
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.21/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.)