 # Decimalize Latitude Longitude

Apr 26th, 2012
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. ;; Answer to Programing Problem: Decimalize Latitude Longitude.
2. ;; Found in http://xahlee.blogspot.com/2012/04/programing-problem decimalize-latitude.html
3.
4. ;; it is very elisp in that it uses a regexp for splitting the
5. ;; strings, and the fact that characters are also numbers in elisp:
6. ;; N=78<S=83 and E=69<W=87
7.
8. (defun decimalize-lat-lon (lat-lon-string)
9.   "Decimalize latitude longitude. Converts a string of the form \"37°26′36.42″N 06°15′14.28″W\" to a list with two numbers of the form (37.44345 -6.253966666666667)."
10.   (let* ((lat-strings (split-string (car (split-string lat-lon-string)) "[^0-9A-Z.]+"))
11.      (lon-strings (split-string (cadr (split-string lat-lon-string)) "[^0-9A-Z.]+"))
12.      (lat-sign (- 1 (* 2(/ (string-to-char (nth 3 lat-strings)) 83))))
13.      (lon-sign (- 1 (* 2(/ (string-to-char (nth 3 lon-strings)) 87))))
14.      (lat (* lat-sign
15.          (+ (string-to-number (nth 0 lat-strings))
16.             (/ (string-to-number (nth 1 lat-strings)) 60.0)
17.             (/ (string-to-number (nth 2 lat-strings)) (* 60.0 60.0)))))
18.      (lon (* lon-sign
19.          (+ (string-to-number (nth 0 lon-strings))
20.             (/ (string-to-number (nth 1 lon-strings)) 60.0)
21.             (/ (string-to-number (nth 2 lon-strings)) (* 60.0 60.0))))))
22.     (list lat lon)))