utm-ups

2023-06-18

Convert coordinates between Latitude/Longitude and UTM or UPS.

Upstream URL

codeberg.org/glv/utm-ups

Author

Guillaume Le Vaillant

License

GPL-3
README
utm-ups

This is a Common Lisp library to convert coordinates between Latitude/Longitude and UTM (Universal Transverse Mercator) or UPS (Universal Polar Stereographic).

1API

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.

UTM zones are represented by positive integers for northern latitudes and negative integers for southern latitudes.

UPS zones are either t for northen latitudes or nil for southern latitudes.

1.1Ellipsoids

*ellipsoid*

Special variable containing the name of the ellipsoid that will be used in computations ("WGS 84" by default).

(ellipsoids) -> list

Return the list of supported ellipsoids.

1.2Main functions

(lat/lon->utm-ups latitude longitude &optional zone) -> list, string

Return the UTM or UPS zone, easting and northing for the given latitude and longitude. The second returned value is the UTM or UPS band. The zone parameter can be used to force in which UTM zone the coordinates will be computed.

(utm/ups->lat/lon zone easting northing) -> list

Return the latitude and longitude for the given UTM or UPS zone, easting and northing.

(band latitude longitude) -> string

Return the UTM or UPS band for the given latitude and longitude.

(format-utm/ups zone easting northing &optional band) -> string

Return UTM or UPS coordinates as a string. If band is not specified, it will be set to + for northern zones and to - for southern zones.

(parse-utm/ups string) -> list

Return the UTM or UPS coordinates represented as a string.

(format-lat/lon latitude longtude &optional format) -> string

Return the coordinates as a string. If format is nil or :dms, d°m's" notation will be used for angles. If format is :dm, d°m' notation will be used. If format is t or :d, decimal notation will be used.

(parse-lat/lon string) -> list

Return the latitude and longitude represented as a string.

1.3UTM specific functions

(lat/lon->utm latitude longitude &optional zone) -> list, string

Return the UTM zone, easting and northing for the given latitude and longitude. The second returned value is the UTM band. The zone parameter can be used to force in which UTM zone the coordinates will be computed.

(utm->lat/lon zone easting northing) -> list

Return the latitude and longitude for the given UTM zone, easting and northing.

(utm-zone latitude longitude) -> integer

Return the UTM zone number for the given latitude and longitude.

(utm-band latitude) -> string

Return the UTM band for the given latitude.

1.4UPS specific functions

(lat/lon->ups latitude longitude) -> list, string

Return the UPS hemisphere, easting and northing for the given latitude and longitude. The second returned value is the UPS band.

(ups->lat/lon northp easting northing) -> list

Return the latitude and longitude for the given UPS hemisphere (northp), easting and northing.

(ups-band latitude longitude) -> string

Return the UPS band for the given latitude and longitude.

2Examples

Load the library:

> (asdf:load-system "utm-ups")
...

Get the UTM coordinates of Madrid:

> (utm-ups:lat/lon->utm/ups 40.433333d0 -3.7d0)
(30 440627.3875554724d0 4476089.9799552625d0)
"T"

> (utm-ups:format-utm/ups 30 440627.3875554724d0 4476089.9799552625d0 "T")
"30T 0440627 4476090"

Get back the latitude and longitude of Madrid:

> (utm-ups:utm/ups->lat/lon 30 440627.3875554724d0 4476089.9799552625d0)
(40.433333001062145d0 -3.700000000011189d0)

> (utm-ups:format-lat/lon 40.433333001062145d0 -3.700000000011189d0)
"40°25'59.9\"N 3°42'00.0\"W"

Get the coordinates of the McMurdo station either in UTM or in UPS:

> (utm-ups:lat/lon->utm -77.846389d0 166.668333d0)
(-58 539204.7698733974d0 1358215.357267417d0)
"C"

> (utm-ups:lat/lon->ups -77.846389d0 166.668333d0)
(NIL 2312265.8557648384d0 682275.9727717754d0)
"B"

Get back the latitude and longitude of the McMurdo station:

> (utm-ups:utm/ups->lat/lon -58 539204.7698733974d0 1358215.357267417d0)
(-77.84638900680321d0 166.66833300105677d0)

> (utm-ups:utm/ups->lat/lon nil 2312265.8557648384d0 682275.9727717754d0)
(-77.84638899999842d0 166.668333d0)

3Tests

The tests require the fiveam library.

(asdf:test-system "utm-ups")

Dependencies (1)

  • fiveam

Dependents (1)

  • GitHub
  • Quicklisp