Author Topic: Point to LAT LON  (Read 7670 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7526
Point to LAT LON
« on: December 19, 2014, 03:31:35 PM »
I've done a little bit of searching for this, but have not found what I've needed. I have a list of points from a GPS unit and would like to convert the LAT & LON to place in a KML file. I used this utility to do the conversion, but would like to know if anyone has come up with a lisp solution.


Thanks.  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ymg

  • Guest
Re: Point to LAT LON
« Reply #1 on: December 19, 2014, 03:53:55 PM »
ronjomp,

What format does your GPS gives you ?

They are usually in Lat long.  KML requires Long Lat in decimal degree.

However if you are getting UTM out of your GPS you could use
the projlib library from Prof. David Allison  and transform back to
Lat. Long.

The projlib library in autolisp is part of the following Zip : http://www.usouthal.edu/geography/allison/mappro/mappro.zip

ymg

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Point to LAT LON
« Reply #2 on: December 19, 2014, 04:03:16 PM »
YMG,
<Disclaimer>I'm a newbie to this so handholding may be necessary ;)</Disclaimer>

The GPS points were given to me by someone else. The format is as follows:

to Latitude   to Longitude   Latitude   Longitude
33.67   111.0916667   334012   1110530


Thanks for your help.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ymg

  • Guest
Re: Point to LAT LON
« Reply #3 on: December 19, 2014, 05:10:54 PM »
Ronjomp,

To use them in a kml all you need to do is
to use them in reverve order that is long first
as 111.0916667 33.67

For example outputting the following
is sufficient to create a placemark at your point:

Code: [Select]
<Placemark>
<name>YourPoint</name>
<Point>
<coordinates>111.01966667,33.67,0</coordinates>
</Point>
</Placemark>


note: no space after the comma.

ymg

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Point to LAT LON
« Reply #4 on: December 19, 2014, 05:22:24 PM »
The points that were supplied to me are these ones: 334012   1110530
The other points were the converted points from the website above.


I was wondering how to do that?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ymg

  • Guest
Re: Point to LAT LON
« Reply #5 on: December 19, 2014, 05:25:54 PM »
ronjomp,

Very likely to mean 111.0530,33.4012

Long would normally be on the interval -180 to 180
While Lat are on -90 to 90

If you paste the text of the placemark code I gave you
into the Myplaces folder in the side window of GE
your placemark should appear.

Double-click on the placemark and GE will zoom to it.

That would be a place in China, nearest city Shaanxi

ymg
« Last Edit: December 19, 2014, 05:49:54 PM by ymg »

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Point to LAT LON
« Reply #6 on: December 19, 2014, 05:39:53 PM »
Maybe a picture will help :) .. How do you calculate the value in yellow?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Point to LAT LON
« Reply #7 on: December 19, 2014, 05:44:40 PM »
use QGIS

Import them

Export them to KML,or KMZ
or many other formats
Be your Best


Michael Farrell
http://primeservicesglobal.com/

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Point to LAT LON
« Reply #8 on: December 19, 2014, 05:54:43 PM »
Figured it out ( I think )  :)

Code - Auto/Visual Lisp: [Select]
  1. ;;1110530
  2. ;; (D 111)(M 05)(S 30)
  3. (alert (strcat "111." (vl-princ-to-string (+ (/ 5 60.) (/ (/ 30 60.) 60.)))))
« Last Edit: December 19, 2014, 06:18:48 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Point to LAT LON
« Reply #9 on: December 19, 2014, 05:57:59 PM »
use QGIS

Import them

Export them to KML,or KMZ
or many other formats


Thanks for the reply Michael, I'll give QGIS a look.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ymg

  • Guest
Re: Point to LAT LON
« Reply #10 on: December 19, 2014, 06:41:12 PM »
rojomp,

It is simply transforming degree minutes second to decimal degree;
Code - Auto/Visual Lisp: [Select]
  1. (defun todec (int / str len d m s)
  2.    (setq str (itoa int)
  3.          len (strlen str)
  4.            s (atof (substr str (- len 2)))
  5.            m (atof (substr str (- len 3) 2))
  6.            d (atof (substr str 1 (- len 4)))
  7.    )     
  8.    (+ d (/ (+ m  (/ s 60)) 60))
  9. )
  10.  
« Last Edit: December 19, 2014, 07:05:15 PM by ymg »

divtiply

  • Guest
Re: Point to LAT LON
« Reply #11 on: December 20, 2014, 07:19:46 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun todec (int / str len d m s)
  2.    (setq str (itoa int)
  3.          len (strlen str)
  4.            s (atof (substr str (- len 2)))
  5.            m (atof (substr str (- len 3) 2))
  6.            d (atof (substr str 1 (- len 4)))
  7.    )     
  8.    (+ d (/ (+ m  (/ s 60)) 60))
  9. )
  10.  

Why not angtof/angtos?

ymg

  • Guest
Re: Point to LAT LON
« Reply #12 on: December 20, 2014, 10:55:20 AM »
divtply,

Your suggestion works also, but this is a carry over from the day of hand calculator.

Angtof returns the result in radians, and the OP needs results in decimal degree.

ymg

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Point to LAT LON
« Reply #13 on: December 22, 2014, 10:29:45 AM »
Thanks for the replies YMG. This is what I ended up cobbling together that seems to work.

Code - Auto/Visual Lisp: [Select]
  1. (defun _kmlpoint (n / d i m s)
  2.   (setq d (* n 0.0001))
  3.   (setq n (rtos (float n) 2 8))
  4.   (setq i (1+ (strlen (itoa (fix d)))))
  5.   (setq m (atof (substr n i 2)))
  6.   (setq s (atof (substr n (+ i 2))))
  7.   (if (minusp d)
  8.     (- (+ (abs (fix d)) (/ m 60.) (/ (/ s 60.) 60.)))
  9.     (+ (fix d) (/ m 60.) (/ (/ s 60.) 60.))
  10.   )
  11. )
  12. ;; (rtos (_kmlpoint -1111007.5) 2 8)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ymg

  • Guest
Re: Point to LAT LON
« Reply #14 on: December 23, 2014, 11:14:55 AM »
ronjomp,

You may have a problem with 03030 as input.

So maybe with a string input intead of an integer:

Code - Auto/Visual Lisp: [Select]
  1. (defun todec (str / d m s n sig)
  2.    (setq n (strlen str)
  3.          s (atof (substr str (- n 2)))
  4.          m (atof (substr str (- n 3) 2))
  5.          d (abs (atoi (substr str 1 (- n 4))))
  6.        sig (if (wcmatch str "-*") -1 1)  
  7.    )     
  8.    (* sig (+ d (/ (+ m  (/ s 60)) 60)))
  9. )
  10.