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

0 Members and 2 Guests are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Point to LAT LON
« Reply #15 on: December 23, 2014, 11:24:38 AM »
Thanks YMG .. I ended up putting this into my function so it can accept a string\real\int
Code - Auto/Visual Lisp: [Select]
  1.   (and (= (type n) 'str) (setq n (atof n)))
  2.   (setq d (* n 0.0001))


On a side note, your function and my function return different results? My numbers match the conversion on this site.
Code - Auto/Visual Lisp: [Select]
  1. ;; (rtos (_kmlpoint "-1111007.5") 2 7)
  2. ;; "-111.1687500"
  3. ;; (todec "-111.1687500")
  4. ;; -112.389

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ymg

  • Guest
Re: Point to LAT LON
« Reply #16 on: December 23, 2014, 12:13:45 PM »
ronjomp,

See this picture:


ronjonp

  • Needs a day job
  • Posts: 7529
Re: Point to LAT LON
« Reply #17 on: December 23, 2014, 12:34:06 PM »
The conversion I need is for points formatted like so ... see below .


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ymg

  • Guest
Re: Point to LAT LON
« Reply #18 on: December 23, 2014, 02:02:52 PM »
ronjomp,

Just modify the n value with vl-string-position:

Code - Auto/Visual Lisp: [Select]
  1. (defun todec (str / d m s n sig)
  2.    (setq n (if (setq n (vl-string-position 46 str)) 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.  


ymg

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Point to LAT LON
« Reply #19 on: December 23, 2014, 02:27:28 PM »
ymg,


Thanks for your help with this  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ymg

  • Guest
Re: Point to LAT LON
« Reply #20 on: December 23, 2014, 02:43:00 PM »
ronjomp,


I got the Season's blues, so trying to keep busy.

ymg  :-)

enderprime

  • Guest
Re: Point to LAT LON
« Reply #21 on: December 24, 2014, 10:58:28 AM »
The way LAT LONG values are determined depends on what survey coordinate system you are in. Because the earth is not a perfect shape there are many models used to represent the surface of the earth, and each system has a different way to represent a virtual "flat" grid that survey crews use while shooting points in the field. These points will have x,y values based on a rather arbitrary reference point for the system, but the system will also have a way to translate those field coordinates into real world LAT LONG values for use in GPS, etc. There are some complex formulas involved which software usually handles for you, and if you start doing these conversions manually you will need to research the methods for each system in order to do it right.

Common coordinate systems include State Plane, UTM, WGS84, etc. As a working example of this, Google Earth uses the WGS84 model by default, and even though this may not matter to the common user the software is assuming coordinates are using that geodetic model in order to provide LAT LONG values. However, if you were to go the opposite direction, and convert the LAT LONG back into system coordinates, those coordinate values will end up being different depending on what system you project into, even though they represent the same location on earth.

I know I'm not being very detailed here, but it is a complex subject and I just wanted to throw out a casual warning about doing the tranforms yourself. Other than ArcGIS and Civil 3D, we usually rely on sites like http://www.earthpoint.us/Convert.aspx to handle quick conversions, mainly because asking a surveyor how these calculations are done leads to a 2 hour discussion.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Point to LAT LON
« Reply #22 on: December 24, 2014, 11:09:34 AM »
The way LAT LONG values are determined depends on what survey coordinate system you are in. Because the earth is not a perfect shape there are many models used to represent the surface of the earth, and each system has a different way to represent a virtual "flat" grid that survey crews use while shooting points in the field. These points will have x,y values based on a rather arbitrary reference point for the system, but the system will also have a way to translate those field coordinates into real world LAT LONG values for use in GPS, etc. There are some complex formulas involved which software usually handles for you, and if you start doing these conversions manually you will need to research the methods for each system in order to do it right.

Common coordinate systems include State Plane, UTM, WGS84, etc. As a working example of this, Google Earth uses the WGS84 model by default, and even though this may not matter to the common user the software is assuming coordinates are using that geodetic model in order to provide LAT LONG values. However, if you were to go the opposite direction, and convert the LAT LONG back into system coordinates, those coordinate values will end up being different depending on what system you project into, even though they represent the same location on earth.

I know I'm not being very detailed here, but it is a complex subject and I just wanted to throw out a casual warning about doing the tranforms yourself. Other than ArcGIS and Civil 3D, we usually rely on sites like http://www.earthpoint.us/Convert.aspx to handle quick conversions, mainly because asking a surveyor how these calculations are done leads to a 2 hour discussion.
ender.prime,

Thanks for the explanation. That site you recommended is what I used for the initial point conversion, but the curious side of me wanted to know how they did the conversion. I did a little bit of reading on converting to State Plane, UTM .. yada yada and my head nearly exploded :) . I'll definitely use software to do those transformations.

Happy Holidays.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

enderprime

  • Guest
Re: Point to LAT LON
« Reply #23 on: December 24, 2014, 11:27:23 AM »
Ha! I asked one of our surveyors at work one day, and that was a mistake. A few hours later I was like man you could have just said "it's complicated and you don't want to program it yourself". If I wanted a degree in surveying I would go back to school eh. It did make me appreciate why ArcGIS was so expensive though.  /shrug

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Point to LAT LON
« Reply #24 on: December 24, 2014, 11:42:33 AM »
I wonder how QGIS that MJ recommended fares against ArcGIS ? The price is definitely right  8) .

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ymg

  • Guest
Re: Point to LAT LON
« Reply #25 on: December 24, 2014, 11:59:53 AM »
ronjomp,

Most everything you do in ArcGIS can be done in QGIS.

And yes, the price is right.

For your coordinates conversion look at at Osgeo4w,
more specifically cs2cs.exe

Converting Lat long to UTM is not that complicated.

What is a mess is the multitudes of projection, ellipsoid
and coordinates system.


ymg

RAYAKMAL

  • Guest
Re: Point to LAT LON
« Reply #26 on: January 05, 2015, 05:31:45 AM »
Just wanna add something to the discussion.
My solution to export UTM Coordinates to KML Format (CAD to GPS Receiver and Google Earth)


Code: [Select]

;; Zoning and Datum are hard coded.  (My region is Zone 48, North Hemisphere)
;; Line Description on KML File is based on Layer Name

;;  Needs to deal with:
;; - Closed Polyline
;; - Automatic LINE COLOR

(defun C:VRTX2KML  ( / olderr )

  (ShowTM "Vertices to File/GPS/Google Earth")
  (NewErrTrap)

  (getmode '("cmdecho" "blipmode" "osmode"))
  (mapcar 'setvar
          '("cmdecho" "blipmode" "osmode")
  '(0 1 0)
  )

  (princ "\nSelect Polyline: ")
  (setq sset (ssget '((0 . "LWPOLYLINE,POLYLINE"))))
  (if sset
     (progn
        ;;
        ;; PREFIX FOR GPS RECEIVER
        ;;
        (setq prefx (getstring "\n. Prefix for Polyline: "))
        (setq flnm  (getstring "\n. Output Filename: "))

        (initget 1)
        (setq wdth  (getint      "\n. POLYLINE Width [1-10]: "))
        ;;
        ;; MANUAL LINE COLOR
        ;;
        (initget "Blue B Red R Green G Yellow Y")
        (setq answr     (getkword    "\n. POLYLINE Color <Red>/Green/Blue/Yellow: "))

        ;;Color and opacity (alpha) values are expressed in hexadecimal notation.
        ;;The range of values for any one color is 0 to 255 (00 to ff). For alpha, 00 is fully transparent and ff is fully opaque.
        ;;The order of expression is aabbggrr, where aa=alpha (00 to ff); bb=blue (00 to ff); gg=green (00 to ff); rr=red (00 to ff).
        ;;For example, if you want to apply a blue color with 50 percent opacity to an overlay, you would specify the following:
        ;;<color>7fff0000</color>,
        ;;where alpha=0x7f, blue=0xff, green=0x00, and red=0x00.

        (cond ((or (= answr "Red") (= answr "R") (= answr nil))
               (setq clr "7F0000FF")
              )
              ((or (= answr "Green") (= answr "G"))
               (setq clr "7F00FF00")
              )
              ((or (= answr "Blue") (= answr "B"))
               (setq clr "7FFF0000")
              )
              ((or (= answr "Yellow") (= answr "Y"))
               (setq clr "7F00FFFF")
              )
        );end cond

        (setq dwgprefx (getvar "DWGPREFIX"))

        (setq flnmCartesian (strcat dwgprefx flnm "-XY.CSV"))
        (setq flnmLatlong   (strcat dwgprefx flnm "-LongLat.CSV"))
        (setq flnmMap       (strcat dwgprefx flnm ".KML"))

        (setq flCartesian (open flnmCartesian "w"))
        (setq flLatLong   (open flnmLatlong "w"))
        (setq flMap       (open flnmMap "w"))

        (vrtx2GPSstakeout sset)

        (close flCartesian)
        (close flLatLong)
        (close flMap)

        (princ (strcat "\n. Data saved to: " flnmCartesian "!"))
        (princ (strcat "\n. Data saved to: " flnmLatlong "!"))
        (princ (strcat "\n. Data saved to: " flnmMap "!"))

     );end progn
  );end if

  (setmode *mod2)
  (OldErrTrap)
  (princ)

)



(defun vrtx2GPSstakeout ( sset / cntr n)

   (WRITESTARTKML clr wdth)

   (setq jumlhpoly   (sslength sset)     ;; Jumlah Polyline
         n            0
   )
   ;; Konter
   (setq idxpoly 1)

   (repeat jumlhpoly
      (setq enm (ssname sset n))
      (setq etype   (dxf-code 0 enm))
      ;;
      ;; Cek Polyline is Close (Google Earth)
      ;;
      (if (= (logand (dxf-code 70 enm) 1) 1)
         (setq Pclose T)
         (setq Pclose nil)
      );end if LOGAND
      (setq desc  (dxf-code 8 enm))  ;; Layer AS DESCRIPTION
      (setq ptlst (getcoords enm))

      (WRITESTARTPLINE desc)
      ;; Konter
      (setq idxvertex 1)
      (setq idx     0)

      (setq ptcartesian '())
      (setq ptlatlong   '())


      (cond ((= etype "LWPOLYLINE")
             (repeat (/ (length ptlst) 2)
                (setq x (nth idx ptlst))
                (setq y (nth (+ idx 1) ptlst))

                (vrtx2GPSWrite)

                (setq idxvertex (+ idxvertex 1))
                (setq idx (+ idx 2))
             );end repeat
             (setq idxpoly (+ idxpoly 1))   
            )
            ((= etype "POLYLINE")
             (repeat (/ (length ptlst) 3)
                (setq x (nth idx ptlst))
                (setq y (nth (+ idx 1) ptlst))

                (vrtx2GPSWrite)

                (setq idxvertex (+ idxvertex 1))
                (setq idx (+ idx 3))
             );end repeat
             (setq idxpoly (+ idxpoly 1))
            )
      );end cond
      (WRITEENDPLINE)
      (setq n (+ n 1))
   );end repeat
   (WRITEENDKML)
   (princ)
);end defun



(defun vrtx2GPSWrite ()

                (setq ptxy (list x y))
                (setq ptcartesian (append ptcartesian (list (list ptxy (strcat prefx (itoa idxpoly) "-" (itoa idxvertex))))))

                ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                ;; Tulis ke FILE X - Y - DESKRIPSI
                (write-line (strcat
                                    (rtos x 2 3)
                                    ","
                                    (rtos y 2 3)
                                    (strcat "," prefx (itoa idxpoly) "-" (itoa idxvertex)) 
                            )
                            flCartesian
                )
                ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                ;; Latitude Longitude
                (setq ptgeo (UTM2LatLong x y 48 F))
                (setq ptlatlong (append ptlatlong     (list (list ptgeo (strcat prefx (itoa idxpoly) "-" (itoa idxvertex))))))

                ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                ;; FILE (LONG-LAT-ELEVATION)
                (write-line (strcat "\t" "\t"
                                    (rtos (Y-OF ptgeo) 2 9)
                                    ","
                                    (rtos (X-OF ptgeo) 2 9)
                                    ",0"                         ;; 2D 
                            )
                            flMap
                )
                ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                ;; GPS FORMAT (LONG-LAT-DESCRIPTION)
                (write-line (strcat "\t" "\t"
                                    (rtos (Y-OF ptgeo) 2 9)
                                    ","
                                    (rtos (X-OF ptgeo) 2 9)
                                    (strcat "," prefx (itoa idxpoly) "-" (itoa idxvertex)) 
                            )
                            flLatLong
                )
                ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

   (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun WRITESTARTKML ( clr wdth )

   (setq AWALKML (strcat
   "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
    <kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\">
    <Document>
     <!-- Begin Style Definitions -->
     <Style id=\"line1\">
       <LineStyle>
         <color>"
          clr
          "</color>
         <width>"
           (itoa wdth)         ;; WIDTH
         "</width>
       </LineStyle>
     </Style>
     <Folder>
       <name>Line Features</name>
       <description>Line Features</description>"
                  )

    )

   (write-line AWALKML flMap)
   (princ)
);END DEFUN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun WRITESTARTPLINE ( desc )

   (setq AWALPline (strcat
   "       <Placemark>
         <description>"

             desc               ;; DESCRIPTION

   "      </description>
         <styleUrl>#line1</styleUrl>
         <LineString>
          <coordinates>"
                   )
   )
   (write-line AWALPLINE flMap)
   (princ)
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun WRITEENDPLINE ( )
   (setq AKHIRPLINE (strcat
    "          </coordinates>
         </LineString>
       </Placemark>"
                       )
   )
   (write-line AKHIRPLINE flMap)
   (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun WRITEENDKML ( )

   (setq AKHIRKML (strcat
   "    </Folder>
   </Document>
   </kml>"
                     )
   )
   (write-line AKHIRKML flMap)
   (princ)
)

;;
;;This function will return a list of coordinates. If the polyline is a LWPOLYLINE entity,
;; the list will be in the form of (x y x y x y x y), and the number of vertices can be determined by ;; dividing the length of the list by
;;If the polyline is a POLYLINE entity (2D or 3D), then the list will be in the form of (x y z x y z x y z),
;; and the number of vertices can be determined by dividing the length of the list by 3.
;;

;;
(defun getcoords (ent)
  (vlax-safearray->list
    (vlax-variant-value
      (vlax-get-property
(vlax-ename->vla-object ent)
"Coordinates"
      )
    )
  )
)

;;
;;(UTM2LatLong 781496 2900000 48 T)


(defun  UTM2LatLong   ( X Y Zone NORTHFLAG  )   ;; NORTHFLAG = TRUE/FALSE

   (if NORTHFLAG
      (setq latd Y)
      (setq latd (- 10000000.00 Y))
   )

   (setq    lond (- 500000.0 X))

   ;; Zone Central Longitude
   (if (> Zone 0)
       (setq ZCL (- (* 6.0 Zone) 183.0))
       (setq ZCL 3.0)
   )


   ;;
   ;;Constant
   ;;
   (setq b    6356752.3142         ) ;; Polar Axis
   (setq a    6378137              ) ;; Equator Radius
   (setq ec   0.0818191909289069   ) ;; Ecc
   (setq e1sq 0.006739496756587    ) ;; E1sq
   (setq K0   0.9996               ) ;; K0



   ;;
   ;; FootPrint Latitude
   ;;
   (setq arc (/ latd K0)           ) ;; Arch Length
   (setq mu  (/ arc (* a (- 1.0  (/ (* 1.0 (expt ec 2)) 4.0)
                                 (/ (* 3.0 (expt ec 4)) 64.0)
                                 (/ (* 5.0 (expt ec 6)) 256.0)
                         )
                    )
             )
   )                                                           ;; =arc/(a*(1-ec^2/4-3*ec^4/64-5*ec^6/256))
   (setq e0  (sqrt (- 1.0 (expt ec 2))))                        ;; =(1-ec^2)^0.5
   (setq e1  (/ (- 1.0 e0) (+ 1.0 e0)))                        ;; =(1-e0)/(1+e0)
   (setq C1  (- (* 3.0 e1 0.5) (/ (* 27.0 (expt e1 3)) 32.0))) ;; =3*ei/2-27*ei^3/32
   (setq C2  (- (/ (* 21.0 e1 e1) 16.0) (/ (* 55.0 e1 e1 e1 e1) 32.0))) ;; =21*ei^2/16-55*ei^4/32
   (setq C3  (/ (* 151.0 e1 e1 e1) 96.0))                      ;; =151*ei^3/96
   (setq C4  (/ (* 1097.0 e1 e1 e1 e1) 512.0))                 ;; =1097*ei^4/512
   (setq phi1 (+ mu (* c1 (sin (* 2.0 mu)))
                    (* c2 (sin (* 4.0 mu)))
                    (* c3 (sin (* 6.0 mu)))
                    (* c4 (sin (* 8.0 mu)))
              )
   )                                                           ;; =mu+c1*SIN(2*mu)+cb*SIN(4*mu)+ccc*SIN(6*mu)+cd*SIN(8*mu)
   ;;
   ;; FINALE FOOTPRINT LATITUDE
   ;;
   (setq lat    (rad2deg phi1))                                ;;=phi1*180/PI()
   (setq latdeg (fix lat))
   (setq latmin (fix (* (- lat latdeg) 60.0)))
   (setq latsec (* 3600.0 (- lat latdeg (/ latmin 60.0))))

   ;;
   (setq Q0 (* e1sq (cos phi1) (cos phi1)))                    ;;=eisq*COS(phi1)^2
   (setq T0 (*      (Tan phi1) (Tan phi1)))                    ;;=TAN(phi1)^2


   (setq N0 (/ a
               (sqrt (- 1.0 (expt (* ec (sin phi1)) 2.0)))
            )
   ) ;;=a/(1-(ec*SIN(phi1))^2)^(1/2)


   (setq R0 (/ (* a (- 1.0 (* ec ec)))
               (expt
                     (- 1.0 (expt (* ec (sin phi1)) 2.0))
                     (/ 3.0 2.0)
               )
            )
   )      ;;=a*(1-ec*ec)/(1-(ec*SIN(phi1))^2)^(3/2)
   (setq D0 (/ lond N0 K0))                                    ;;=lond/(n0*k0)

   ;;
   ;;Coefficients for Calculating Latitude
   ;;

   (setq Fact1  (* N0 (/ (Tan Phi1) R0))) ;;=n0*TAN(phi1)/r0
   (setq Fact2  (* D0 D0 0.5))            ;;=dd0*dd0/2
   (setq Fact3  (/ (* (+ 5.0 (* 3.0 T0)
                             (* 10.0 Q0)
                             (* -4.0 Q0 Q0)
                             (* -9.0 e1sq)   
                      )
                      D0 D0 D0 D0
                   )
                   24.0
                 )     
   )                        ;;=(5+3*t0+10*Q0-4*Q0*Q0-9*eisq)*dd0^4/24
   (setq Fact4   (/ (* (+ 61.0 (* 90.0 T0)
                               (* 298.0 Q0)
                               (* 45.0 T0 T0)
                               (* -252.0 e1sq)
                               (* -3.0 Q0 Q0)
                       )
                       D0 D0 D0 D0 D0 D0
                    )
                    720.0
                  )
                                         
   )                        ;;=(61+90*t0+298*Q0+45*t0*t0-252*eisq-3*Q0*Q0)*dd0^6/720



   ;;
   ;;Coefficients for Calculating Longitude
   ;;

   (setq LoFact1  D0)
   (setq LoFact2  (/ (* (+ 1.0 (*  2.0 T0) Q0)
                        D0 D0 D0
                     )
                     6.0
                  )
   )                        ;; =(1+2*t0+Q0)*dd0^3/6
   (setq LoFact3  (/ (* (+ 5.0 (* -2.0 Q0)
                               (* 28.0 T0)
                               (* -3.0 Q0 Q0)
                               (*  8.0 e1sq)
                               (* 24.0 T0 T0)
                         )
                         D0 D0 D0 D0 D0
                      )
                      120.0
                   )

    )                       ;;=(5-2*Q0+28*t0-3*Q0^2+8*e1sq+24*t0^2)*dd0^5/120

   (setq DeltaLongRad (/ (+ LoFact1 (* -1.0 LoFact2) Lofact3)
                         (Cos Phi1)
                      )
   )                  ;; =(lof1-lof2+lof3)/COS(phi1)
   (setq DeltaLongDec (rad2deg DeltaLongRad))

   (setq LatRad      (- phi1 (* Fact1 (+ Fact2 Fact3 Fact4))))  ;;=(phi1-fact1*(fact2+fact3+fact4))


   (setq LatitudeIs  (rad2deg LatRad))
   (setq LongitudeIs (- ZCL DeltaLongDec))


;   (princ (rtos LatitudeIs  2 8))
;   (princ "\t")
;   (princ (rtos LongitudeIs 2 8))
    (list (* -1.0 LatitudeIs) LongitudeIs) ;;
)



(defun showTM ( txt ) (graphscr)
  (princ (strcat "\n. " txt))
  (princ ". (Copyright of ARY HIMAWAN S. 1990)")
)
(defun NewErrTrap () (setq olderr *error* *error* @hs_err) (princ))
(defun OldErrTrap () (setq *error* olderr olderr nil) (princ))

;;o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~o
;; Save Restore System variable setting                         
;; Example : (getmode '("cmdecho" "blipmode" "osmode" etc...etc....))
;; Example : (setmode *mod2)         
;;o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~o

(defun getmode (mod1)
  (setq *mod2 '()) ; create global variable to store setting
  (repeat (length mod1)
    (setq *mod2
   (append *mod2 (list (list (car mod1) (getvar (car mod1)))))
    )
    (setq mod1 (cdr mod1)) ; go to next element in list
  )
)

(defun setmode (mod1)
  (repeat (length mod1)
    (setvar (caar mod1) (cadar mod1)) ; extract setting and reset
    (setq mod1 (cdr mod1))
  )
)

;;o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~o
;; FIND DXF GROUP
;;o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~o

(defun dxf-code (code enm /) (cdr (assoc code (entget enm))))


« Last Edit: January 05, 2015, 06:39:47 PM by RAYAKMAL »

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Point to LAT LON
« Reply #27 on: January 05, 2015, 11:39:21 AM »
RAYAKMAL,

Thanks for the reply. It appears the code you posted is missing a few functions needed.

getmode
setmode
dxf-code
utm2latlong

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

RAYAKMAL

  • Guest
Re: Point to LAT LON
« Reply #28 on: January 05, 2015, 06:41:44 PM »
RAYAKMAL,

Thanks for the reply. It appears the code you posted is missing a few functions needed.

getmode
setmode
dxf-code
utm2latlong

Checked and Edit my previous post.
You can find the complete code on the the attachment.

sanju2323

  • Newt
  • Posts: 68
Re: Point to LAT LON
« Reply #29 on: January 06, 2015, 01:48:58 AM »
This Lisp File to Convert Kml

(defun c:dwg2kml (/ coords line_from_kml fn)
  (setq old_osmode (getvar "osmode"))
  (setvar "osmode" 17408)
  (setq   idfilename         ;get the file name to convert
    (getfiled "Choose KML File Name"
         ""
         "kml"
         33
    )
  )
  (setq fn (open idfilename "r"))
  (setq line_from_kml (read-line fn))
  (while (/= line_from_kml nil)
    (while (and   (/= line_from_kml nil)
      (not (vl-string-search "<Polygon>" line_from_kml))
      )
      (setq line_from_kml (read-line fn))
    )
    (setq line_from_kml (read-line fn))
    (while (and   (/= line_from_kml nil)
      (not (vl-string-search "<coordinates>" line_from_kml))
      )
      (setq line_from_kml (read-line fn))
    )
    (setq coords "")
    (while (and   (/= line_from_kml nil)
      (not (vl-string-search "</coordinates>" line_from_kml))
      )
      (setq line_from_kml (read-line fn))
      (if (not (vl-string-search "</coordinates>" line_from_kml))
   (setq coords (strcat coords " " line_from_kml))
      )
    )
    (setq coords (string2list (vl-string-translate "," " " coords) 32))
    (setq coords (xyList->ListofPoints3D coords))
    (if   (/= coords nil)
      (progn (command "_pline")
        (foreach pt coords
          (command pt)
        )
        (command "")
      )
    )
    (spin)
    )
  (setvar "osmode" old_osmode)
  (princ)
)
(defun xyList->ListOfPoints3D (coordList / ptlist)
;;;3D
  (while coordList
    (setq ptlist    (append ptlist
             (list (list   (distof (car coordList) 2)
               (distof (cadr coordList) 2)
               ;(distof (caddr coordList) 2) drop to 2D
              )
             )
          ) ;_ end of append
     coordList (cdddr coordList)   ; input list is still 3D
    ) ;_ end of setq
  ) ;_ end of while
  ptlist
)

;;;converts string to a list using deliminators             
;;;Takes two arguments, first the string and then the integer
;;;representing the ascii code for the delimiter.           
;;;eg (string2list "Hello World" 32) = ("Hello" "World")   
;;;32 for " ", 44 for "," 59 for ";" etc.                   
(defun string2list (f_string delim / f_cur f_len f_loop f_ls f_str)
  (setq   f_ls nil
   f_str ""
  )
  (setq f_loop 0)
  (repeat (strlen f_string)
    (progn
      (setq f_loop (1+ f_loop))
      (setq f_cur (substr f_string f_loop 1))
      (if (= (ascii f_cur) delim)
   (if (/= f_str "")
     (progn (setq f_ls (append f_ls (list f_str)))
       (setq f_str "")
     )
   )
   (setq f_str (strcat f_str f_cur))
      )
    )
  )
  (if (/= f_str "")
    (setq f_ls (append f_ls (list f_str)))
  )
  f_ls
)
(defun SPIN ()
  (setq   a_s (if   a_s
         a_s
         4
       )
  )
  (princ
    (strcat
      "\r"
      (cadr
   (member
     (rem (setq a_s (1+ a_s)) 4)
     '(0 "|" 1 "/" 2 "-" 3 "\\")
   )
      )
    )
  )
)