Jose Ramon Rubio
Jose Ramon Rubio

Reputation: 29

Javascript to convert degrees, to decimal, and UTM

I´m trying to convert Degrees, Minutes and Seconds, to decimal degrees, and finally to UTM. Is there any example or library available for this purpose?

Thanks!

Upvotes: 1

Views: 743

Answers (1)

Terry Lennox
Terry Lennox

Reputation: 30675

There are some useful libraries for doing this kind of thing, in particular geolib and utm-latlng.

Once we import these we can convert from Degrees, Minutes, Seconds with geolib and then to UTM with utm-latlng:

const geolib = require("geolib");
const UTM = require("utm-latlng");
const utm = new UTM();

const input = { lat: "34° 3′ 12.96″ N", lon: "118° 14′ 34.8″ W" };
const decimalCoords = geolib.toDecimal(input);

console.log("Input:", input);
console.log("Degrees/Minutes/Seconds To Decimal:", decimalCoords);
console.log("UTM:", utm.convertLatLngToUtm(decimalCoords.lat, decimalCoords.lon, 0));

Upvotes: 1

Related Questions