unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Jean Louis <bugs@gnu.support>
To: arthur miller <arthur.miller@live.com>
Cc: Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: dms2dd Re: Expanding list into string within a command
Date: Sun, 6 Dec 2020 23:34:52 +0300	[thread overview]
Message-ID: <X81AbBRQCNLbdGO/@protected.rcdrun.com> (raw)
In-Reply-To: <AM0PR06MB65779109E8EB3527FACCED5E96CF0@AM0PR06MB6577.eurprd06.prod.outlook.com>

I have actually forgot that I have already transitioned Common Lisp to
Emacs Lisp to convert DMS to DD coordinates.

(defun geo/dms-parse (dms)
  (let* ((cardinal (cond ((string-match "N" dms) "N")
			 ((string-match "S" dms) "S")
			 ((string-match "E" dms) "E")
			 ((string-match "W" dms) "W")
			 (t (error "No cardinal direction found"))))
	 (parts (string-replace-non-digits-for-spaces dms))
	 (parts (string-trim parts))
	 (parts (string-replace-shorten-spaces parts))
	 (parts (split-string parts))
	 (degrees (string-to-number (car parts)))
	 (minutes (string-to-number (cadr parts)))
	 (seconds (string-to-number (caddr parts))))
    (list degrees minutes seconds cardinal)))

(defun geo/dms2dd-degrees (d)
  (truncate d))

(defun geo/dms2dd-minutes (m)
  (float (/ m 60.0)))

(defun geo/dms2dd-seconds (s)
  (float (/ s 3600.0)))

(defun geo/dms2dd (dms)
  "Converts DMS value to DD geo value"
  (let* ((dms (geo/dms-parse dms))
	 (degrees (car dms))
	 (minutes (cadr dms))
	 (seconds (caddr dms))
	 (cardinal (cadddr dms))
	 (dd (+ (geo/dms2dd-degrees degrees)
		(geo/dms2dd-minutes minutes)
		(geo/dms2dd-seconds seconds))))
    (cond ((string= "S" cardinal) (- dd))
	  ((string= "W" cardinal) (- dd))
	  (t dd))))



      reply	other threads:[~2020-12-06 20:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-06 19:46 Expanding list into string within a command Jean Louis
2020-12-06 19:57 ` arthur miller
2020-12-06 20:30   ` Jean Louis
2020-12-06 19:57 ` [solved] " Jean Louis
2020-12-06 20:07 ` arthur miller
2020-12-06 20:34   ` Jean Louis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=X81AbBRQCNLbdGO/@protected.rcdrun.com \
    --to=bugs@gnu.support \
    --cc=arthur.miller@live.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).