What is mgrs?
The 'mgrs' npm package provides functionality for converting between latitude/longitude coordinates and Military Grid Reference System (MGRS) coordinates. It is useful for applications that require precise location data in a standardized grid format.
What are mgrs's main functionalities?
Convert Lat/Lon to MGRS
This feature allows you to convert latitude and longitude coordinates to MGRS coordinates. The code sample demonstrates converting the coordinates of Los Angeles (34.0522, -118.2437) to an MGRS string.
const mgrs = require('mgrs');
const latLon = [34.0522, -118.2437];
const mgrsCoord = mgrs.forward(latLon);
console.log(mgrsCoord); // Output: '11SLT7432279348'
Convert MGRS to Lat/Lon
This feature allows you to convert MGRS coordinates back to latitude and longitude. The code sample demonstrates converting the MGRS string '11SLT7432279348' back to the coordinates of Los Angeles.
const mgrs = require('mgrs');
const mgrsCoord = '11SLT7432279348';
const latLon = mgrs.toPoint(mgrsCoord);
console.log(latLon); // Output: [34.0522, -118.2437]
Convert UTM to MGRS
This feature allows you to convert UTM (Universal Transverse Mercator) coordinates to MGRS. The code sample demonstrates converting a UTM coordinate to an MGRS string.
const mgrs = require('mgrs');
const utmCoord = [500000, 4649776, 33];
const mgrsCoord = mgrs.UTMtoMGRS(utmCoord);
console.log(mgrsCoord); // Output: '33TWN0000000000'
Convert MGRS to UTM
This feature allows you to convert MGRS coordinates to UTM coordinates. The code sample demonstrates converting the MGRS string '33TWN0000000000' to a UTM coordinate.
const mgrs = require('mgrs');
const mgrsCoord = '33TWN0000000000';
const utmCoord = mgrs.MGRStoUTM(mgrsCoord);
console.log(utmCoord); // Output: [500000, 4649776, 33]
Other packages similar to mgrs
utm
The 'utm' package provides functionality for converting between latitude/longitude and UTM coordinates. While it does not support MGRS directly, it can be used in conjunction with other packages to achieve similar results.
geodesy
The 'geodesy' package offers a wide range of geospatial functions, including conversions between different coordinate systems such as UTM, MGRS, and latitude/longitude. It is more comprehensive than 'mgrs' but may be more complex to use.
proj4
The 'proj4' package is a JavaScript library for performing cartographic transformations, including conversions between various coordinate systems. It is highly versatile and supports a wide range of projections, including UTM and MGRS.
mgrs
Utility for converting between WGS84 lat/lng and MGRS coordinates, spunoff from proj4js
has 3 methods
- forward, takes an array of
[lon,lat]
and optional accuracy and returns an mgrs string - inverse, takes an mgrs string and returns a bbox.
- toPoint, takes an mgrs string, returns an array of '[lon,lat]'
install dev dependencies with
npm install
test with
npm test
build with
npm run build
Licensed under the MIT license except:
Portions of this software are based on a port of components from the OpenMap
com.bbn.openmap.proj.coords Java package. An initial port was initially created
by Patrice G. Cappelaere and included in Community Mapbuilder
(http://svn.codehaus.org/mapbuilder/), which is licensed under the LGPL license
as per http://www.gnu.org/copyleft/lesser.html. OpenMap is licensed under the
this license agreement
references: