/mgrs

Convert coordinates between Latitude/Longitude and MGRS

Primary LanguageCommon LispGNU General Public License v3.0GPL-3.0

mgrs

The active repository is at https://codeberg.org/glv/mgrs

This is a Common Lisp library to convert coordinates between Latitude/Longitude and MGRS.

API

In the library, latitude and longitude are represented by real numbers (degrees), positive for northern latitude and eastern longitudes, and negative for southern latitude and western longitudes.

(lat/lon->mgrs latitude longitude &optional precision) -> string

Return the MGRS locator for the given latitude and longitude. The precision (in meters) of the locator can be 1, 10, 100, 1000, 10000.

(mgrs->lat/lon locator &optional center-p) -> list

Return the latitude and longitude for the southwest corner of the given MGRS locator square, or the center of the square if center-p is not nil.

Examples

Load the library:

> (asdf:load-system "mgrs")
...

Get the MGRS locator of Munich:

> (mgrs:lat/lon->mgrs 48.146660d0 11.60833d0)
"32UPU9401035891"

Same thing with a lower precision (100 meters):

> (mgrs:lat/lon->mgrs 48.146660d0 11.60833d0 100)
"32UPU940358"

Get back the latitude and longitude of Munich:

> (mgrs:mgrs->lat/lon "32UPU9401035891")
(48.146655723267834d0 11.60832570541976d0)

Tests

The tests require the fiveam library.

(asdf:test-system "mgrs")