ExMgrs (ex_mgrs v0.0.5)
A library for converting between latitude/longitude coordinates and MGRS (Military Grid Reference System) coordinates.
This module provides functions to convert between decimal degree coordinates (latitude/longitude) and MGRS coordinate strings using the WGS84 ellipsoid.
Summary
Functions
Formats an MGRS string with proper spacing.
Converts latitude/longitude coordinates to MGRS format.
Converts MGRS coordinates to latitude/longitude format.
Functions
Formats an MGRS string with proper spacing.
Takes an MGRS string (with or without spaces) and returns it formatted with standard spacing: GZD + space + 100km Square + space + Easting + space + Northing
Parameters
mgrs: MGRS coordinate string (with or without spaces)
Returns
{:ok, formatted_string}on success{:error, reason}if the MGRS string is invalid
Examples
iex> ExMgrs.format_mgrs("11SLT8548562848")
{:ok, "11S LT 85485 62848"}
iex> ExMgrs.format_mgrs("11S LT 85485 62848")
{:ok, "11S LT 85485 62848"}
iex> ExMgrs.format_mgrs("11SLT854628")
{:ok, "11S LT 854 628"}
Converts latitude/longitude coordinates to MGRS format.
Parameters
lat: Latitude in decimal degrees (-90.0 to 90.0)lon: Longitude in decimal degrees (-180.0 to 180.0)precision: Number of digits for easting/northing (1-5, default: 5)
Returns
{:ok, mgrs_string}on success{:error, reason}on failure
Examples
iex> ExMgrs.latlon_to_mgrs(34.0, -118.24)
{:ok, "11SLT8548562848"}
Converts MGRS coordinates to latitude/longitude format.
Parameters
mgrs: MGRS coordinate string
Returns
{:ok, {latitude, longitude}}on success where coordinates are in decimal degrees{:error, {0.0, 0.0}}on failure
Examples
iex> {:ok, {lat, lon}} = ExMgrs.mgrs_to_latlon("11SLT8548562848")
...> {Float.round(lat, 5), Float.round(lon, 5)}
{34.0, -118.24}