Created
May 10, 2011 17:59
-
-
Save rcampbell/964996 to your computer and use it in GitHub Desktop.
Conversion from Decimal Degree to DMS (Degrees, Minutes, Seconds) in Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; See http://en.wikipedia.org/wiki/Geographic_coordinate_conversion | |
(defn dms [type degrees] | |
{:pre [(#{:latitude :longitude} type)]} | |
"Conversion from Decimal Degree to DMS (Degrees, Minutes, Seconds)" | |
(let [total-sec (Math/round (* (Math/abs degrees) 60 60)) | |
total-min (quot total-sec 60) | |
sec (rem total-sec 60) | |
min (rem total-min 60) | |
deg (quot total-min 60)] | |
{:direction (case type | |
:latitude (if (neg? degrees) :south :north) | |
:longitude (if (neg? degrees) :west :east )) | |
:degrees deg | |
:minutes min | |
:seconds sec})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment