Movable Type Home Page

Movable Type Scripts


Geodesy Library – migrating from v1

Version 2 of the geodesy library uses ES modules (referenced using import statements). This has enabled better structured code covering wider functionality (such as modern TRFs in addition to historical datums, and some ellipsoidal n-vector functions).

These notes set out breaking changes moving from version 1 of the library to version 2.

Full documentation for the library is available at www.movable-type.co.uk/scripts/geodesy-library.html

Using the library

In the browser:

v1 v2 (in all current mainstream browsers)
<!doctype html><title>geodesy</title><meta charset="utf-8">
<script defer src="https://cdn.jsdelivr.net/npm/geodesy@1.1.3/latlon-spherical.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/geodesy@1.1.3/dms.min.js"></script>
<script>
    const p1 = new LatLon(50.06632, -5.71475);
    const p2 = new LatLon(58.64402, -3.07009);
    const mid = p1.midpointTo(p2);
    console.assert(mid.toString() == '54°21′44″N, 004°31′51″W');
</script>
<!doctype html><title>geodesy</title><meta charset="utf-8">
<script type="module">
    import LatLon from 'https://cdn.jsdelivr.net/npm/geodesy@2.2.0/latlon-spherical.min.js';
    const p1 = new LatLon(50.06632, -5.71475);
    const p2 = new LatLon(58.64402, -3.07009);
    const mid = p1.midpointTo(p2);
    console.assert(mid.toString() == '54°21′44″N, 004°31′51″W');
</script>

In Node.js:

v1 v2 (currently requires esm package to load ES-modules)
const LatLon = require('geodesy/latlon-spherical.js');
const p1 = new LatLon(50.06632, -5.71475);
const p2 = new LatLon(58.64402, -3.07009);
const mid = p1.midpointTo(p2);
console.assert(mid.toString() == '54°21′44″N, 004°31′51″W');
        
import LatLon from 'geodesy/latlon-spherical.js';
const p1 = new LatLon(50.06632, -5.71475);
const p2 = new LatLon(58.64402, -3.07009);
const mid = p1.midpointTo(p2);
console.assert(mid.toString() == '54°21′44″N, 004°31′51″W');
        

Further examples are included in the GitHub README.

Class/method breaking changes

Initial capital indicates static class method, initial lower-case indicates instantiated object.

dms.js
Dms.parseDMS() Dms.parse()
Dms.toDMS() Dms.toDms()
default DMS separator is narrow no-break space (U+202F)
 
latlon-spherical.js
constructor requires new
latlon.bearingTo() latlon.initialBearingTo()
all methods accepts LatLon points in variety of formats
 
latlon-ellipsoidal.js ⇒ latlon-ellipsoidal-datum.js
constructor requires new
new Cartesian class extends Vector3d
LatLon.datum LatLon.datums
LatLon.datum[d].ellipsoid LatLon.datums[d].ellipsoids
vector3d.toLatLonE() cartesian.toLatLon()
 
latlon-vincenty.js ⇒ latlon-ellipsoidal-vincenty.js
 
latlon-vectors.js ⇒ latlon-nvector-spherical.js
constructor requires new
new Nvector class extends Vector3d
latlon.toVector() latlon.toNvector()
vector3d.toLatLonS() Nvector.toLatLon()
latlon.bearingTo() latlon.initialBearingTo()
latlon.isBetween() latlon.isWithinExtent()
latlon.enclosedBy() latlon.isEnclosedBy()
 
utm.js
constructor requires new
Utm.toLatLonE() Utm.toLatLon()
 
mgrs.js
constructor requires new
 
osgridref.js
uses instantiated objects rather than static methods
OsGridRef.osGridToLatLon() osGridRef.toLatLon()
OsGridRef.latLonToOsGrid() latlon.toOsGrid()
 

If there are any omissions, please let me know at scripts@movable-type.co.uk.