Jump to content

Recommended Posts

Posted

I am trying to figure how to (not show) the negative (-) within the Longitude value.

 

Example:

Latitude 56d 42' 22"

Longitude -82d 21' 26"

 

Thank you for the help!

 

; Convert Decimal Degrees to dms.
(defun convertDDdms (x1 / deg mins sec)
  (setq deg (rtos (fix X1) 2 0)                                    ;- degrees
        mins (rtos (abs (fix (* (- X1 (fix X1)) 60))) 2 0)         ; - minutes
        sec (rtos (abs (* (- (* X1 60) (fix (* x1 60))) 60)) 2 2)  ;- seconds
  )
  (strcat deg "d " mins "' " sec "\"")
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun c:Coords	(/ as_cor ll lat lon pnt)
  (setq as_cor (ade_projgetwscode))
  (if (/= "" as_cor)			 
    (progn
      (ade_projsetsrc as_cor)
      (ade_projsetdest "LL84")		
      
      (while (not  (setq pnt (getpoint "\nSelect a point: "))))
        (progn
	(setq ll (ade_projptforward pnt))
	(setq lat (car ll)
	      lon (car (cdr ll))
	)
	(setq desc (ade_projgetinfo "LL84" "description"))
	(alert (strcat "Conversion:"
                       "\n " 
		       "\nLatitude:" (convertDDdms lon) 
                       "\nLongitude: " (convertDDdms lat) 
                       "\nHorz Datum: NAD83"
	       )
	)
	(princ)
      )
    )
    (asg_coor)
  )
)

 

Posted (edited)

Didn't you post this awhile ago? I took out the neg for the mins and sec but degrees it needs to be kept if your working in the southern hemisphere.

 

change the following

(setq deg (rtos (fix X1) 2 0)

to

(setq deg (rtos (abs (fix X1)) 2 0)

 

then it will always be positive.

Edited by mhupp
put abs in the wrong place
Posted

Yup you are right. I finally got back to it.

 

Thank you for showing me this. However, I am getting an error

 

(defun convertDDdms (x1 / deg mins sec)
  ;;(setq deg (rtos (fix X1) 2 0)
    (setq deg (abs (rtos (fix X1) 2 0))                                    ;- degrees
        mins (rtos (abs (fix (* (- X1 (fix X1)) 60))) 2 0)         ; - minutes
        sec (rtos (abs (* (- (* X1 60) (fix (* x1 60))) 60)) 2 2)  ;- seconds
  )
  (strcat deg "d " mins "' " sec "\"")
)



command: Select a point: ; error: bad argument type: numberp: "40"

 

When I tried to match the below code.

 

  ;;(setq deg (rtos (fix X1) 2 0)
    (setq deg (rtos (abs (fix X1) 2 0)) ;;<<<---                                   ;- degrees
        mins (rtos (abs (fix (* (- X1 (fix X1)) 60))) 2 0)         ; - minutes
        sec (rtos (abs (* (- (* X1 60) (fix (* x1 60))) 60)) 2 2)  ;- seconds
                                                
                                                
command: Select a point: ; error: too many arguments 

 

Posted
37 minutes ago, rcb007 said:

I am trying to figure how to (not show) the negative (-) within the Longitude value.

 

Example:

Latitude 56d 42' 22"

Longitude -82d 21' 26"

............

 

Your position is ambiguous.

 

How will others know whether you are North or South of the Equator, or even West or East of the Prime Meridian?

Posted (edited)
1 hour ago, rcb007 said:

Thank you for showing me this. However, I am getting an error

 

The error isn't with convertDDdms

its most likely here in the function ade_projptforward when it sets the lat and lon

 

(while (not  (setq pnt (getpoint "\nSelect a point: "))))
        (progn
	(setq ll (ade_projptforward pnt))
	(setq lat (car ll)
	      lon (car (cdr ll))
	)

 

my guess its setting them as strings and not integers or doubles because that error is saying "40" isn't a number.

"40" is a number to humans but its in string value so the program cant add, subtract, multiple, or divide it until you convert it into an real

 

Test the following and see the difference

; Convert Decimal Degrees to dms.
(defun convertDDdms (x1 / deg mins sec)
  (setq deg (rtos (fix X1) 2 0)  ;- degrees
        mins (rtos (abs (fix (* (- X1 (fix X1)) 60))) 2 0)         ; - minutes
        sec (rtos (abs (* (- (* X1 60) (fix (* x1 60))) 60)) 2 2)  ;- seconds
  )
  (strcat deg "d " mins "' " sec "\"")
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun c:CooWnumbers (/ as_cor ll lat lon pnt)
  (setq lat -82.16197462765378
        lon 56.07939295460651 
  )
  (alert (strcat "Conversion:"
                 "\n "
                 "\nLatitude:" (convertDDdms lon)
                 "\nLongitude: " (convertDDdms lat)
                 "\nHorz Datum: NAD83"
         )
  )
  (princ)
)


(defun c:CooWstring (/ as_cor ll lat lon pnt)
  (setq lat "-82.16197462765378"
        lon "56.07939295460651"
  )
  (alert (strcat "Conversion:"
                 "\n "
                 "\nLatitude:" (convertDDdms lon)
                 "\nLongitude: " (convertDDdms lat)
                 "\nHorz Datum: NAD83"
         )
  )
  (princ)
)
Edited by mhupp
  • Like 1
Posted

The CooWstring seems to generate an error.

 

Command: CooWstring
; error: bad argument type: numberp: "56.07939295460651"

 

Command: CooWnumbers 

Did pop with the alert box and no errors.

 

 

Posted (edited)
8 minutes ago, rcb007 said:

The CooWstring seems to generate an error.

 

Command: CooWstring
; error: bad argument type: numberp: "56.07939295460651"

 

Command: CooWnumbers 

Did pop with the alert box and no errors.

 

 

 

 CooWstring = Coords with String values

like i said your other function is probably setting string values instead of integer values.

 

in lisp

"56.07939295460651" = string

56.07939295460651 = integer

 

you could try the following but not 100% it would work

 

(setq lat (atof (car ll))
      lon (atof (car (cdr ll)))
)

 

 

Edited by mhupp
Posted

Like you said earlier, is it as simple a converting the string over to an interger?

 

Something similar to this? I basically just added the atoi into the setq.

 

(defun c:CooWstring (/ as_cor ll lat lon pnt)
  (setq lat (atoi "-82.16197462765378")
        lon (atoi "56.07939295460651")
  )
  (alert (strcat "Conversion:"
                 "\n "
                 "\nLatitude:" (convertDDdms lon)
                 "\nLongitude: " (convertDDdms lat)
                 "\nHorz Datum: NAD83"
         )
  )
  (princ)
)

 

Posted
10 minutes ago, rcb007 said:

Like you said earlier, is it as simple a converting the string over to an interger?

 

Something similar to this? I basically just added the atoi into the setq.

 


(defun c:CooWstring (/ as_cor ll lat lon pnt)
  (setq lat (atoi "-82.16197462765378")
        lon (atoi "56.07939295460651")
  )
  (alert (strcat "Conversion:"
                 "\n "
                 "\nLatitude:" (convertDDdms lon)
                 "\nLongitude: " (convertDDdms lat)
                 "\nHorz Datum: NAD83"
         )
  )
  (princ)
)

 

 

looked it up atoi only sets whole numbers you want to use atof so it will set everything after the .

 

lat (atoi "-82.16197462765378")  lat = -82

lat (atof "-82.16197462765378")  lat = -82.16197462765378

Posted

Ok. So if I use the (atof) function. I should be able to apply what you mentioned above.

 

  (setq lat (atof "-82.16197462765378")
        lon (atof "56.07939295460651")
  )



; Convert Decimal Degrees to dms.
(defun convertDDdms (x1 / deg mins sec)
(setq deg (rtos (fix X1) 2 0)  ;- degrees
        mins (rtos (abs (fix (* (- X1 (fix X1)) 60))) 2 0)         ; - minutes

to this.

; Convert Decimal Degrees to dms.
(defun convertDDdms (x1 / deg mins sec)
(setq deg (abs (rtos (fix X1) 2 0))  ;- degrees
        mins (rtos (abs (fix (* (- X1 (fix X1)) 60))) 2 0)         ; - minutes

 

Then getting the following:

 

Command: coowstring
; error: bad argument type: numberp: "56"
Command:

Posted (edited)

abs needs to wrap fix x1

 

(setq deg (rtos (abs (fix X1)) 2 0)  ;- degrees

 

also its still saying "56" that is a string. if your not reloading the lisp its running the old code quickest way to fix it is to open up windows explorer to where the lisp file is and drag it into AutoCAD you will get a load message and will be running the latest code.

Edited by mhupp
Posted (edited)

BOOM! Got it! Thank you for your time, help and explanation. I m sorry if it seems like I was chasing my tail around and around.

This works.

 

; Convert Decimal Degrees to dms.
(defun convertDDdms (x1 / deg mins sec)
(setq deg (rtos (abs (fix X1)) 2 0)  ;- degrees
        mins (rtos (abs (fix (* (- X1 (fix X1)) 60))) 2 0)         ; - minutes
        sec (rtos (abs (* (- (* X1 60) (fix (* x1 60))) 60)) 2 2)  ;- seconds
  )
  (strcat deg "d " mins "' " sec "\"")
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun c:CooWnumbers (/ as_cor ll lat lon pnt)
  (setq lat -82.16197462765378
        lon 56.07939295460651 
  )
  (alert (strcat "Conversion:"
                 "\n "
                 "\nLatitude:" (convertDDdms lon)
                 "\nLongitude: " (convertDDdms lat)
                 "\nHorz Datum: NAD83"
         )
  )
  (princ)
)


(defun c:CooWstring (/ as_cor ll lat lon pnt)
  (setq lat (atof "-82.16197462765378")
        lon (atof "56.07939295460651")
  )
  (alert (strcat "Conversion:"
                 "\n "
                 "\nLatitude:" (convertDDdms lon)
                 "\nLongitude: " (convertDDdms lat)
                 "\nHorz Datum: NAD83"
         )
  )
  (princ)
)

 

Edited by rcb007
Posted
2 minutes ago, rcb007 said:

BOOM! Got it! Thank you for your time, help and explanation. I m sorry if it seems like I was chasing my tail around and around.

This works.

 

Thats just a stripped down code so i could run it on my end. you need to update your original code with the changes to see if it really workds

Posted

This is what I have. It seems like it works with what we have talked about.

 

; Convert Decimal Degrees to dms.
(defun convertDDdms (x1 / deg mins sec)
  (setq deg (rtos (abs (fix X1)) 2 0)                                    ;- degrees
        mins (rtos (abs (fix (* (- X1 (fix X1)) 60))) 2 0)         ; - minutes
        sec (rtos (abs (* (- (* X1 60) (fix (* x1 60))) 60)) 2 2)  ;- seconds
  )
  (strcat deg "d " mins "' " sec "\"")
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun c:Coords	(/ as_cor ll lat lon pnt)
  (setq as_cor (ade_projgetwscode))
  (if (/= "" as_cor)			 
    (progn
      (ade_projsetsrc as_cor)
      (ade_projsetdest "LL84")		
      
      (while (not  (setq pnt (getpoint "\nSelect a point: "))))
        (progn
	(setq ll (ade_projptforward pnt))
	(setq lat (car ll)
	      lon (car (cdr ll))
	)
	(setq desc (ade_projgetinfo "LL84" "description"))
	(alert (strcat "Conversion:"
                       "\n " 
		       "\nLatitude:" (convertDDdms lon) 
                       "\nLongitude: " (convertDDdms lat) 
                       "\nHorz Datum: NAD83"
	       )
	)
	(princ)
      )
    )
    (asg_coor)
  )
)

 

Posted (edited)
(defun convertDDms (n)
    (strcat
	(rtos (fix (setq n (abs n))) 2 0) "d "
	(rtos (fix (setq n (* (- n (fix n)) 60))) 2 0) "' "
	(rtos (* (- n (fix n)) 60) 2 2) "\""
	)
    )

 

If negative doesn't matter, you can avoid all the 'abs' by setting it in the beginning first.

Edited by Jonathan Handojo
  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...