# Remove Negative from Longitude

## Recommended Posts

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)
(if (/= "" as_cor)
(progn

(while (not  (setq pnt (getpoint "\nSelect a point: "))))
(progn
(setq lat (car ll)
lon (car (cdr ll))
)
"\n "
"\nLatitude:" (convertDDdms lon)
"\nLongitude: " (convertDDdms lat)
)
)
(princ)
)
)
(asg_coor)
)
)```

##### Share on other sites
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
##### Share on other sites

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 ```

##### Share on other sites
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"

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

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

##### Share on other sites
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 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
)
"\n "
"\nLatitude:" (convertDDdms lon)
"\nLongitude: " (convertDDdms lat)
)
)
(princ)
)

(defun c:CooWstring (/ as_cor ll lat lon pnt)
(setq lat "-82.16197462765378"
lon "56.07939295460651"
)
"\n "
"\nLatitude:" (convertDDdms lon)
"\nLongitude: " (convertDDdms lat)
)
)
(princ)
)```
Edited by mhupp
##### Share on other sites

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.

##### Share on other sites
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
##### Share on other sites

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")
)
"\n "
"\nLatitude:" (convertDDdms lon)
"\nLongitude: " (convertDDdms lat)
)
)
(princ)
)```

##### Share on other sites
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")
)
"\n "
"\nLatitude:" (convertDDdms lon)
"\nLongitude: " (convertDDdms lat)
)
)
(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

##### Share on other sites

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:

##### Share on other sites
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
##### Share on other sites
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
)
"\n "
"\nLatitude:" (convertDDdms lon)
"\nLongitude: " (convertDDdms lat)
)
)
(princ)
)

(defun c:CooWstring (/ as_cor ll lat lon pnt)
(setq lat (atof "-82.16197462765378")
lon (atof "56.07939295460651")
)
"\n "
"\nLatitude:" (convertDDdms lon)
"\nLongitude: " (convertDDdms lat)
)
)
(princ)
)```

Edited by rcb007
##### Share on other sites
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

##### Share on other sites

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)
(if (/= "" as_cor)
(progn

(while (not  (setq pnt (getpoint "\nSelect a point: "))))
(progn
(setq lat (car ll)
lon (car (cdr ll))
)
"\n "
"\nLatitude:" (convertDDdms lon)
"\nLongitude: " (convertDDdms lat)
)
)
(princ)
)
)
(asg_coor)
)
)```

##### Share on other sites
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

## 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.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.