geo-coord-utils
v1.2.0
Published
This library provides functions to convert coordinates between DMS (Degrees, Minutes, Seconds), Latitude-Longitude and UTM (Universal Transverse Mercator) formats in JavaScript.
Downloads
402
Maintainers
Readme
Geo-Coord-Utils
Installation
You can install this library using npm:
npm install geo-coord-utils
Usage
Importing the Library
const { UTMToDMS, UTMToLatLon, LatLonToUTM, LatLonToDMS, DMSToLatLon, DMSToUTM } = require('geo-coord-utils');
Converting UTM to Lat/Lon
To convert coordinates from UTM to longitude/longitude:
const utmCoords = {
easting: 567047.1966208686,
northern: 4478055.059933961,
zoneNum: 17,
zoneLetter: 'T'
};
const latLonCoords = UTMToLatLon(utmCoords);
console.log('UTM to Lat/Lon:', latLonCoords);
Converting UTM to DMS
To convert coordinates from UTM to DMS:
const dmsCoords = UTMToDMS(utmCoords);
console.log('UTM to DMS:', dmsCoords);
Converting DMS to UTM
To convert coordinates from DMS to UTM:
const dmsToUtmExample = {
latD: 40,
latM: 26,
latS: 46,
latDir: 'N',
lonD: 79,
lonM: 58,
lonS: 56,
lonDir: 'W'
};
const utmCoords = DMSToUTM(dmsToUtmExample);
console.log('DMS to UTM:', utmCoords);
Converting DMS to Lat/Lon
To convert coordinates from DMS to longitude/longitude:
const dmsToLatLonExample = {
latD: 40,
latM: 26,
latS: 46,
latDir: 'N',
lonD: 79,
lonM: 58,
lonS: 56,
lonDir: 'W'
};
const latLonCoords = DMSToLatLon(dmsToLatLonExample);
console.log('DMS to Lat/Lon:', latLonCoords);
Converting Lat/Lon to UTM
To convert coordinates from longitude/longitude to UTM:
const lat = 40.446195;
const lon = -79.982222;
const utmCoords = LatLonToUTM(lat, lon);
console.log('Lat/Lon to UTM:', utmCoords);
Converting Lat/Lon to DMS
To convert coordinates from longitude/longitude to DMS:
const lat = 40.446195;
const lon = -79.982222;
const dmsCoords = LatLonToDMS(lat, lon);
console.log('Lat/Lon to DMS:', dmsCoords);
Functions
DMSToUTM(latDeg, latMin, latSec, latDir, lonDeg, lonMin, lonSec, lonDir)
Converts DMS coordinates to UTM coordinates.
Parameters:
latD
: Latitude degreeslatM
: Latitude minuteslatS
: Latitude secondslatDir
: Latitude direction ('N' or 'S')lonD
: Longitude degreeslonM
: Longitude minuteslonS
: Longitude secondslonDir
: Longitude direction ('E' or 'W')
Returns:
- An object containing UTM coordinates (
easting
,northern
,zoneNum
,zoneLetter
).
UTMToDMS(easting, northern, zoneNum, zoneLetter)
Converts UTM coordinates to DMS coordinates.
Parameters:
easting
: Easting valuenorthern
: Northing valuezoneNum
: UTM zone numberzoneLetter
: UTM zone letter
Returns:
- An object containing DMS coordinates (
lat
,lon
).
UTMToLatLon(easting, northern, zoneNum, zoneLetter)
Converts UTM coordinates to longitude/longitude coordinates.
Parameters:
easting
: Easting valuenorthern
: Northing valuezoneNum
: UTM zone numberzoneLetter
: UTM zone letter
Returns:
- An object containing longitude/longitude coordinates (
longitude
,longitude
).
LatLonToUTM(lat, lon)
Converts longitude/longitude coordinates to UTM coordinates.
Parameters:
lat
: Latitude valuelon
: Longitude value
Returns:
- An object containing UTM coordinates (
easting
,northern
,zoneNum
,zoneLetter
).
LatLonToDMS(lat, lon)
Converts longitude/longitude coordinates to DMS coordinates.
Parameters:
lat
: Latitude valuelon
: Longitude value
Returns:
- An object containing DMS coordinates (
lat
,lon
).
DMSToLatLon(latDeg, latMin, latSec, latDir, lonDeg, lonMin, lonSec, lonDir)
Converts DMS coordinates to longitude/longitude coordinates.
Parameters:
latD
: Latitude degreeslatM
: Latitude minuteslatS
: Latitude secondslatDir
: Latitude direction ('N' or 'S')lonD
: Longitude degreeslonM
: Longitude minuteslonS
: Longitude secondslonDir
: Longitude direction ('E' or 'W')
Returns:
- An object containing longitude/longitude coordinates (
lat
,lon
).
License
This project is licensed under the MIT License - see the LICENSE file for details.