dms2dec

GPS degrees, minutes, seconds coordinates to decimal

Usage no npm install needed!

<script type="module">
  import dms2dec from 'https://cdn.skypack.dev/dms2dec';
</script>

README

dms2dec.js

Build status NPM downloads NPM version Node version Dependency status

Degrees, minutes, seconds (sexagesimal) to decimal GPS positions. Useful for parsing PGS exif tags in geotagged images.

Install

Node.JS

npm install dms2dec --save
var dms2dec = require('dms2dec');

Web

<script language="JavaScript" src="/dms2dec.js"></script>

Usage

[latDec, lonDec] = dms2dec(String lat, String latRef, String lon, String lonRef);

Params

  • lat – latitude in "degrees, minutes, seconds" format
  • lagRef – latitude hemisphere reference (N or S)
  • lon – longitude in "degrees, minutes, seconds" format
  • lonRef – longitude hemisphere reference (E or W)

Return

  • latDec – latitude converted into decimal format
  • lonDec – longitude converted into decimal format

Parse dms strings

var dec = dms2dec("60/1, 21/1, 4045/100", "N", "5/1, 22/1, 1555/100", "E");
// dec[0] == 60.36123611111111, dec[1] == 5.370986111111111

// without spaces or commas in the dms strings are also supported
var dec = dms2dec("60/1,21/1,4045/100", "N", "5/1,22/1,1555/100", "E");
var dec = dms2dec("60/1 21/1 4045/100", "N", "5/1 22/1 1555/100", "E");

Parse dms arrays

var dec = dms2dec(["60/1", "21/1", "4045/100"], "N", ["5/1", "22/1", "1555/100"], "E");
// dec[0] == 60.36123611111111, dec[1] == 5.370986111111111

dms arrays as decimal

var dec = dms2dec([60, 21, 40.45], "N", [5, 22, 15.55], "E");
// dec[0] == 60.36123611111111, dec[1] == 5.370986111111111

GeoJSON

NB! Remember that GeoJSON stores coordinates in reversed order (longitude, latitude) which means you have to reverse the order of the coordinates returned from dms2dec().

var geojson = {
  type: 'Point',
  coordinates: dms2dec(lat, latRef, lon, lonRef).reverse()
};