Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to convert utm to latlong

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
bahman.jf.68
1862 Views, 7 Replies

how to convert utm to latlong

Hi all, is there any lisp or Autocad command to convert a utm coordinate to latlong ?

7 REPLIES 7
Message 2 of 8
Sea.haven
in reply to: bahman.jf.68

Simple answer is probably yes. The issue is there are so many factors in converting a x y to lat long. 1st is its world dependant, all sorts of factors creep in. 

 

You may need to use an external program, did you google.

Message 3 of 8
braudpat
in reply to: bahman.jf.68

Hello

 

Are you running ACAD MAP or ACAD CIVIL because these products have some ADE functions for Re-Projection !?

 

If you have a "NEW" license ACAD, since the version 2019 the package is called "ACAD including Specialized Toolsets" and ACAD MAP is included !

 

---- System requirements for ACAD 2004-2022 ----

https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/System...

 

The Health, Bye, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 4 of 8
hak_vz
in reply to: bahman.jf.68

You may try cs2cs from Proj.org 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 5 of 8

You see here my solution 100%AutoLisp.The original source Was in C2 MathEquation/s.

 

 (princ)
    (setq con_princeax "")                       ;;;rem: you append one string each lines
  (setq;|a55647|;
	 kpi 3.14159265358979323846
	 con_pi kpi
	 ktwopi 6.2831853071795865
	 khalfpi (/ pi 2.0)
	 con_khalfpi (/ pi 2.0)
	 con_1pi4 (* pi 0.25)
	 con_3pi4 (* pi 0.75)
	 con_5pi4 (* pi 1.25)
	 con_7pi4 (* pi 1.75)
	 con_p4pi 12.56637061435917
	 con_p2pi 6.28318530717958647692
	 con_p2dpi 0.63661977236758134308
	 con_sqrt2 1.41421356237309504880
	 con_1sqrt2 0.70710678118654752440
	 con_1six 0.16666666666666666667
	 con_1three (* con_1six 2.0)
	 con_2sqrtpi 1.12837916709551257390) 
    ;;;Inp: a251=int,
    ;;;rem:     a251=tchar.
    ;;;rem:   (vla-setlayoutstoplot plot salayout)
    ;;;rem:   (setq errmsg (vl-catch-all-apply 'vla-PlotToDevice (list plot "\\\\RW-PRN01\\RICOH")))
    ;;;rem:   (if (vl-catch-all-error-p errmsg)
    ;;;rem:    (prompt (strcat "\nERROR: " (vl-catch-all-error-message errmsg)))
    ;;;rem:   ))
(setq kHereAiciHeirIciAqui 0767004316 ;;rem: my-phone romanian
      errno 5100
      erprv nil)
;;;__ __ . __ __ . __ __ . __ __ . __ __ .__ __ . __ __ . __ __ . __ __ . __ __ .__ __ . __ __ . __ __ . __ __ . __ __ .
(defun dfn_var_isstr0(a094 default / rr) ;_ASSERT_OK
  (setq;|a1660|;
	 rr (if (=  (type a094) (quote SYM)) (eval a094) a094)
	 rr (if (=  (type rr) (quote STR)) rr default)) 
rr)


(defun if_int(a025 default / reti guru)  ;_ASSERT_OK
  (setq;|a2680|;
	 guru (quote INT)
	 reti (if (=  (type a025) (quote SYM)) (eval a025) a025)
	 reti (if (/= (type reti) guru) default reti)) 
reti)

(defun asserte(a251 / rr) ;_ASSERT_OK
  (setq;|a4476|;
	 errno 0
	 acad__assertNo (if (/= (type acad__assertNo) (quote INT)) 0 (+ acad__assertNo 1))) (if (/= a251 nil) (setq;|a4564|;
	 erprv erlsp
	 erlsp (strcat "@" a251 "<" (itoa acad__assertNo) ">"))) (if (=  acad__assertNo kHereAiciHeirIciAqui) (alert (strcat "Hi! eBreakPoint kHereAiciHeirIciAqui=" (itoa kHereAiciHeirIciAqui)))) 
erlsp)

;;;__ __ . __ __ . __ __ . __ __ . __ __ .__ __ . __ __ . __ __ . __ __ . __ __ .__ __ . __ __ . __ __ . __ __ . __ __ .
;;;Inf: Here is starting routine
(deFun C:Q2() ;_ASSERT_OK
  (setq;|a5534|;
	 acad__assertNo (if_int acad__assertNo 0)) (if (and  (<  acad__assertNo (- 10)) (/= const_error nil)) (setq;|a5598|;
	 kHereAiciHeirIciAqui (- acad__assertNo))) (setq;|a5616|;
	 acad__assertNo 0) 
 (winmain_pp_utmcoosmall_run)
)
(prompt "\nCommand.com : Q2[enter]\n")
(defun winmain_pp_utmcoosmall_run( / );_ASSERT_OK
  (setq;|a6452|;
	 const_ppfiletmp (if (=  (type const_ppfiletmp) (quote STR)) const_ppfiletmp "")) (if (<  (strlen const_ppfiletmp) 3) (_wndproc) (terpri)) 
;------------------------;$
  (setq utmx1 451602.19)
;------------------------
;------------------------;$
  (setq utmy1 4519076.99)
;------------------------
;------------------------;$
  (setq zoneutm1 "33n")
;------------------------
;------------------------Stdcall "pp_utm_watermocasin "
  (setq _ax (pp_utm_watermocasin utmx1 utmy1 zoneutm1))
;------------------------
;------------------------;$
  (setq arxgate _ax)
;------------------------
;------------------------;$
  (setq utmx2 (getreal "enter utmx2: "))
;------------------------
;------------------------;$
  (setq utmy2 (getreal "enter utmy2: "))
;------------------------
;------------------------;$
  ;;;;;;;;;;(setq zoneutm2 (getstring "enter utm zone: "))
;------------------------
;------------------------;$
  (setq zoneutm2 "32n")
;------------------------
;------------------------Stdcall "pp_utm_watermocasin "
  (setq _ax (pp_utm_watermocasin utmx2 utmy2 zoneutm2))
;------------------------
;------------------------;$
  (setq arxgate (strcat arxgate _ax))
;------------------------
;------------------------;$
  (setq utmx3 (getreal "enter utmx3: "))
;------------------------
;------------------------;$
  (setq utmy3 (getreal "enter utmy3: "))
;------------------------
;------------------------;$
  ;;;;;;;;(setq zoneutm3 (getstring "enter utm zone: "))
;------------------------
;------------------------;$
  (setq zoneutm3 "31n")
;------------------------
;------------------------Stdcall "pp_utm_watermocasin "
  (setq _ax (pp_utm_watermocasin utmx3 utmy3 zoneutm3))
;------------------------
;------------------------;$
  (setq arxgate (strcat arxgate _ax))
;------------------------
;------------------------Stdcall "pp_dorin2tex "
  (setq _ax (pp_dorin2tex ))
;------------------------
;------------------------;$
  (setq arxgate (strcat _ax arxgate))
;------------------------
;------------------------;$
  (alert arxgate)
;------------------------
;;;rem:----------------------------------------------------------------------
  (command) (command ".UNDO" "_END") (princ "\nEnd")  
rr)
;;;rem:---User Labels----cad_apages----- 
;;;rem:---(call_copy_source)----cad_apages----- 

;;  .--/|
;;o~ "   `.. - - - - .
;; `~~\                `.
;;     `.   }    {    /\|
;;       \  |~- -~\   |
;;       || |     >> /
;;\\|/   ||_|    ;;;rem:_/        \|/
;;                      \|;;;rem:
;;;Inf: ZwCad da eroare la getenv("TEMP") result=nil
;;;Out:rr:string=("".get temporally directory)(nil.none)
;;;Eg1:"C:/TEMP/"
(defun str_pathtemp ( / rr e f k)  (asserte "A131")
  (setq;|a15514|;
	 rr nil
	 f (dfn_var_isstr (getenv "TEMP"))) (if (and  (not rr) f) (setq;|a15578|;
	 rr f)) (setq;|a15594|;
	 f (if (not f) (dfn_var_isstr (getenv "TMP")) f)) (if (and  (not rr) f) (setq;|a15656|;
	 rr f)) (setq;|a15676|;
	 f (dfn_var_isstr (getvar "TEMPPREFIX"))
	 f (if (not f) (dfn_var_isstr (getenv "TMP")) f)) (setq;|a15758|;
	 f (dfn_var_isstr (getvar "XLOADPATH"))
	 f (if (not f) (dfn_var_isstr (getenv "TMP")) f)) (if (=  rr nil) (setq;|a15852|;
	 rr "")) (setq;|a15868|;
	 k (strlen rr)) (if (>  k 2) (progn  (while (and  (>  k 1) (=  (substr rr k 1) " ")) (setq;|a15964|;
	 rr (substr rr 1 (- k 1))) (progn (while (and  (>  k 1) (wcmatch rr "*[\\]*")) (if (=  (substr rr k 1) "\\") (setq;|a16090|;
	 rr (strcat (substr rr 1 (- k 1)) "/" (substr rr (+ k 1))))) (setq;|a16182|;
	 k (- k 1)))) (setq;|a16204|;
	 c (substr rr (strlen rr))) (if (/= c "/") (setq;|a16254|;
	 rr (strcat rr "/")))))) rr) 
;;---------------+---------------
;;          ___ /^[___              _
;;         /|^+----+   |#___________;;;rem:
;;       ( -+ |____|    ______-----+/
;;        ==_________--'            \
;;          ~_|___|__
;;
;;;Out:rr:adsretint=(0.unknown)
;;;rem:    (1.program in IntelliCAD)
;;;rem:    (2.AutoCAD)
;;;rem:    (3.ZwCad)
;;;ByA:DragneA
(Defun dfn_cadver_isicad( / rr ac lc uc)
  (setq;|a18065|;
	 ac (dfn_var_isstr (getvar "PROGRAM"))
	 rr 0) (if ac (progn  (setq;|a18135|;
	 lc (strcase ac T)
	 uc (strcase ac)) (if (wcmatch uc "ICAD*") (setq;|a18215|;
	 rr 1)) (if (wcmatch lc "acad*") (setq;|a18255|;
	 rr 2)) (if (wcmatch lc "*zwc*") (setq;|a18295|;
	 rr 3)))) 
rr)
;; ,~~_
;; |/\ =_ _ ~
;;  _( )_( )\~~
;;  \,\  _|\ \~~~
;;     \`   \

(defun syst_setvars(listavar / rr kg lg cf om)  ;_ASSERT_OK
  (setq;|a21136|;
	 kg 0
	 lg listavar) (progn (setq;|a21170|;
	 rr nil) (while (/= lg nil) (if (/= lg nil) (progn  (setq;|a21224|;
	 con_lastvar (caar lg)
	 om (getvar con_lastvar)
	 rr (if om (append rr (list con_lastvar om)) rr)
	 cf (cadar lg)
	 om (if (=  cf nil) nil om)
	 om (if (=  cf T) nil om)
	 om (if om (setvar con_lastvar cf) nil)
	 kg (if om (+ kg 1) kg)))) (setq;|a21522|;
	 lg (cddr lg)))) 
rr)
;;((^--__
;;| /\  --___ __
;;   (  /  \  ) \\
;;   / |~~~~/  \  \\
;; /    \ /      \
(defun _wndproc( / rr io kj su bya lz)
  (setq su ""
        bya "(c)VlaxCompiler v1.0"
  )
  (setq;|a24836|;
	 const_ppfiletmp (str_pathtemp)
	 str_pathtempA const_ppfiletmp
	 const_ppfiletmp (strcat const_ppfiletmp "pagefile.sys")) (setq;|a24914|;
	 rr (atof (getvar "ACADVER"))) (if (<  rr 14.0) (alert " Warning Minim Req : AutoCAD 14.0 or highter")) (if (<  rr 15.0) (setq;|a24990|;
	 *error* nil)) (setq;|a25006|;
	 io (command "_.undo" "Auto" "On")) (setq;|a25046|;
	 kj (dfn_cadver_isicad)) (if (=  kj 2) (setq;|a25086|;
	 io (list (vl-load-com) (textscr)))) (setq;|a25134|;
	 _ax rr) (command ".UNDO" "_BEGIN") (setq;|a25170|;
	 lz (list (list "MODEMACRO" bya) (list "UCSICON" 1) (list "ISAVEBAK" 1) (list "SAVETIME" 15) (list "BLIPMODE" 0))) (setq;|a25306|;
	 _ppcx_init_vars (syst_setvars lz)) (setq;|a25338|;
	 _pp_var1chkm nil
	 lz nil
	 dfn_var_chkC "") 
rr)
;; ,
;;/,`\
;;` | \____\\
;; _(      ) \
;; \-\~~~_|\  \
;;    \ `   \  `
;;    `     `
;Lib:free


    ;;;Inf: UTM to LatLon test
    ;;;Eg1: (pp_utmirneb 451602.19 4519076.99 "33N")
    ;;;ByA: Water Moccasin
(defun pp_utm_watermocasin(utmX utmY utmZone / rr latitude longitude len isnorthhemisphere diflat diflon c_sa c_sb e2 e2cuadrada c x y s v a1 a2 j2 j4 j6 alfa beta gama bm epsi eps nab senoheps delt tao zone $db $ol jcxz)
  (setq;|a36819|;
	 $db "\nError"
	 latitude 0
	 longitude 0
	 len (php_strlen utmZone)) (if (>  len 1) (progn  (setq;|a36995|;
	 isNorthHemisphere (substr utmZone len 1)
	 diflat (- 0.00066286966871111111111111111111111111)
	 diflon (- 0.0003868060578)
	 utmZone (substr utmZone 1 (- len 1))) (setq;|a37117|;
	 c_sa 6378137.000000) (setq;|a37133|;
	 c_sb 6356752.314245) (setq;|a37149|;
	 e2 (/ (math_pow (- (math_pow c_sa 2) (math_pow c_sb 2)) 0.5) c_sb)) (setq;|a37225|;
	 e2cuadrada (math_pow e2 2)) (setq;|a37257|;
	 c (/ (math_pow c_sa 2) c_sb)) (setq;|a37295|;
	 x (- utmX 500000)) (setq;|a37317|;
	 isNorthHemisphere (if (>  isNorthHemisphere "N") T nil)) (setq;|a37353|;
	 y (if isNorthHemisphere utmY (- utmY 10000000))) (setq;|a37387|;
	 zone (atoi utmZone)) (setq;|a37411|;
	 s (- (* zone 6.0) 183.0)) (setq;|a37439|;
	 lat (/ y (* 6366197.724 0.9996))) (setq;|a37467|;
	 v (* (/ c (math_pow (+ 1 (* e2cuadrada (math_pow (cos lat) 2))) 0.5)) 0.9996)) (setq;|a37541|;
	 a (/ x v)) (setq;|a37563|;
	 a1 (sin (* 2 lat))) (setq;|a37587|;
	 a2 (* a1 (math_pow (cos lat) 2))) (setq;|a37627|;
	 j2 (+ lat (/ a1 2.0))) (setq;|a37655|;
	 j4 (/ (+ (* 3 j2) a2) 4.0)) (setq;|a37689|;
	 j6 (/ (+ (* 5 j4) (* a2 (math_pow (cos lat) 2))) 3.0)) (setq;|a37747|;
	 alfa (* (/ 3.0 4.0) e2cuadrada)) (setq;|a37775|;
	 beta (* (/ 5.0 3.0) (math_pow alfa 2))) (setq;|a37819|;
	 gama (* (/ 35.0 27.0) (math_pow alfa 3))) (setq;|a37863|;
	 bm (* 0.9996 c (- (+ (- lat (* alfa j2)) (* beta j4)) (* gama j6)))) (setq;|a37927|;
	 b (/ (- y bm) v)) (setq;|a37955|;
	 epsi (* (/ (* e2cuadrada (math_pow a 2)) 2.0) (math_pow (cos lat) 2))) (setq;|a38023|;
	 eps (* a (- 1 (/ epsi 3.0)))) (setq;|a38057|;
	 nab (+ (* b (- 1 epsi)) lat)) (setq;|a38091|;
	 senoheps (/ (- (math_exp eps) (math_exp (- eps))) 2.0)) (setq;|a38137|;
	 delt (atan (/ senoheps (cos nab)))) (setq;|a38163|;
	 tao (atan (/ (* (cos delt) (sin nab)) (cos nab)))) (setq;|a38199|;
	 longitude (+ (* (/ delt Math_PI) 180) s)) (setq;|a38233|;
	 latitude (* (/ (+ lat (* (- (+ 1 (* e2cuadrada (math_pow (cos lat) 2))) (* (/ 3.0 2.0) e2cuadrada (sin lat) (cos lat) (- tao lat))) (- tao lat))) Math_PI) 180.0)) (setq;|a38355|;
	 rr (strcat "\nLatitud: " (rtos latitude 2 12) "\tLongitud: " (rtos longitude 2 12))) (setq;|a38451|;
	 $db rr) (str_princ $db))) (princ "\nAll done okai") 
$db)
;Lib:free


(defun pp_dorin2tex( / $rr)
 (setq $rr 
      "Can someone please help translate the  C ++ code in Lisp.  
There is a code to go from UTM Coordinates to lang long. 
«zlib=../cl_aclayer/geomcalc/2020/pp_utmcoosmall.vlax»"
 )
 (setq $rr (if_str $rr "Library_logmessageFAILED\n"))
$rr)
;Lib:free

;;;Out:("...".is STR maxim 512characters)
;;;rem:    ;(nil.else)
;;;Lib:free
(Defun dfn_var_isstr (a094 / rr) ;_ASSERT_OK
  (setq;|a39470|;
	 rr (if (=  (type a094) (quote STR)) a094 nil)) 
rr)
;Lib:free


;;;Out:rr:int=(-2.error a111 is not string type)
;;;rem:           (-1. the  var is nil)
;;;rem:           (else.okai)

(defun php_strlen(a111 / rr es) 
  (if (=  a111 nil) (setq;|a40874|;
	 rr (- 1)) (progn  (setq;|a40900|;
	 es (if (=  (type a111) (quote SYM)) (eval a111) a111)
	 rr (if (=  (type es) (quote STR)) (strlen es) (- 2)))))  
rr)
;Lib:free

    ;;;Inp: a295: real or int numarul 
    ;;;Out:rr:tchar=(error)
    ;;;rem:      ;:real=okai
(defun math_exp(a295 / rr) (asserte "A295")
  (setq;|a41730|;
	 rr (dfn_var_isnumber a295 nil)
	 rr (if (=  rr nil) (rxtrace "a295errA<>RTREAL") (exp rr))) 
rr)
;Lib:free


(defun math_piA ( / rr)
  (setq;|a42315|;
	 rr (* 4.0 (atan 1.0))
	 math_pi rr) 
rr)
(setq math_pi (math_piA))
(setq math.pi math_pi)
;Lib:free

    ;;;Inp: Functie de calcul al unui numar la o putere
    ;;;rem:     inlocuieste functia din lisp expt
    ;;;rem:function pwrr(x,y:real):real;(* real la putere reala *)
    ;;;rem:begin   pwrr:=exp(y*ln(x));end;
    ;;;rem:
    ;;;Inp: nr41: real sau int numarul care e ridicat la puterea
    ;;;rem:     la37:real sau int puterea
(defun math_pow(a294 la37 / rr qq ww) (asserte "A294")
  (setq;|a44060|;
	 rr nil
	 qq (dfn_var_isnumber a294 rr)
	 ww (dfn_var_isnumber la37 rr)) (if (=  qq nil) (setq;|a44156|;
	 rr (rxtrace "a294errA<>RTREAL"))) (if (=  ww nil) (setq;|a44196|;
	 rr (rxtrace "a294errL<>RTREAL"))) (if (and  qq ww) (setq;|a44234|;
	 rr (expt qq ww))) 
rr)
;Lib:free

    ;;;Inf:Display a multiple princ.
    ;;;Inp:a101:list=(if first string is nil then execute the command textscr()
    ;;;rem:               before)
    ;;;Out:nil

(defun str_princ2(a101 / rr ad gq)  (asserte "A101")
  (if (=  nil (dfn_var_isstr con_princeax)) (setq;|a46204|;
	 con_princeax "")) (if (dfn_var_isstr a101) (setq;|a46244|;
	 qq (list (princ a101) (princ con_princeax))) (progn  (if (=  (car a101) nil) (setq;|a46326|;
	 gq (textscr)
	 a101 (cdr a101))) (foreach ad a101 (princ ad) (princ con_princeax)))) 

nil)
(defun str_princ(a101 / ) (str_princ2 a101))
;Lib:free

(defun if_str(s386 elseuser / $rr tip) ;;_ASSERT_OK
  (setq;|a48159|;
	 tip (quote STR)
	 $rr (if (=  (type s386) (quote SYM)) (eval s386) s386)) (setq;|a48237|;
	 $rr (if (/= (type $rr) tip) elseuser $rr)) (if (and $rr (=  elseuser 1)) (progn  (setq;|a48313|;
	 romania "You must sure the str MustHave>0"
	 $rr (if (>  (strlen $rr) 0) $rr elseuser)))) 
$rr)
;Lib:free

             (setq acet_error "")  ;;;rem: you store here all errors
(defun rxtrace(ai_error / rr qs fj qi aqui qs)
  (setq;|a51491|;
	 rr "\n"
	 qs (quote STR)) (if (/= (type acet_error) qs) (setq;|a51555|;
	 acet_error rr)) (if (/= (type ai_error) qs) (setq;|a51593|;
	 errno 5100
	 ai_error "")) (setq;|a51635|;
	 acad__assertNo (if_int acad__assertNo 0)
	 aqui (itoa acad__assertNo)) (if (/= (type erlsp) qs) (setq;|a51703|;
	 erlsp "a257errA")) (setq;|a51725|;
	 rr (strcat erlsp ":" aqui)) (setq;|a51771|;
	 acet_error (strcat acet_error "\n" rr ai_error "**")) (if (=  ai_error "!") (progn  (princ "\n<acet_error>") (princ acet_error) (princ "\n</acet_error>") (grread))) 
rr)
;Lib:free


;;;inp: k120=int, real,sym
;;;Out:rr(nr.is Integer or real)(deft.else)
;;;ByA:DragneAdrian

(defun dfn_var_isnumber(k120 deft / rr ak) ;_ASSERT_OK
  (setq;|a53444|;
	 rr k120
	 ak (type rr)) (if (=  ak (quote SYM)) (setq;|a53506|;
	 rr (eval rr)
	 ak (type rr))) (setq;|a53548|;
	 rr (if (or  (=  ak (quote INT)) (=  ak (quote REAL))) rr deft)) 
rr)
;Lib:free


;;;rem:   Inf: pi2= este un pi rotunjit la care nr de zecimale influenteazá
;;;rem:        Calculeaza constanta PI
;;;rem:     #define PI      ((double)3.14159265358979323846)

;Lib:free

    ;;;Inf: (type(a025)==quote(INT))
    ;;;Out:rr(1.is Integer)(nil.else)
    ;;;ByA:DragneAdrian2015

(defun if_int(a025 default / reti guru)  ;_ASSERT_OK
  (setq;|a57028|;
	 guru (quote INT)
	 reti (if (=  (type a025) (quote SYM)) (eval a025) a025)
	 reti (if (/= (type reti) guru) default reti)) 
reti)
;Lib:free
 ;;;{$R -cad_amain_eof T229@:057294run="devcinfo.exe
(prompt "\ncommand.com: GEO2[enter]\n")
;;;rem:End of file
;;;</-cad_amain_eof>

 

 

Message 6 of 8
diagodose2009
in reply to: hak_vz

 (princ)
    (setq con_princeax "")                       ;;;rem: you append one string each lines
  (setq;|a31431|;
	 kpi 3.14159265358979323846
	 con_pi kpi
	 ktwopi 6.2831853071795865
	 khalfpi (/ pi 2.0)
	 con_khalfpi (/ pi 2.0)
	 con_1pi4 (* pi 0.25)
	 con_3pi4 (* pi 0.75)
	 con_5pi4 (* pi 1.25)
	 con_7pi4 (* pi 1.75)
	 con_p4pi 12.56637061435917
	 con_p2pi 6.28318530717958647692
	 con_p2dpi 0.63661977236758134308
	 con_sqrt2 1.41421356237309504880
	 con_1sqrt2 0.70710678118654752440
	 con_1six 0.16666666666666666667
	 con_1three (* con_1six 2.0)
	 con_2sqrtpi 1.12837916709551257390) 
(setq kHereAiciHeirIciAqui 0767004316 ;;rem: my-phone romanian
      errno 5100
      erprv nil)

(defun dfn_var_isstr0(a094 default / rr) ;_ASSERT_OK
  (setq;|a1546|;
	 rr (if (=  (type a094) (quote SYM)) (eval a094) a094)
	 rr (if (=  (type rr) (quote STR)) rr default)) 
rr)


(defun if_int(a025 default / reti guru)  ;_ASSERT_OK
  (setq;|a2566|;
	 guru (quote INT)
	 reti (if (=  (type a025) (quote SYM)) (eval a025) a025)
	 reti (if (/= (type reti) guru) default reti)) 
reti)

(defun asserte(a251 / rr) ;_ASSERT_OK
  (setq;|a4362|;
	 errno 0
	 acad__assertNo (if (/= (type acad__assertNo) (quote INT)) 0 (+ acad__assertNo 1))) (if (/= a251 nil) (setq;|a4450|;
	 erprv erlsp
	 erlsp (strcat "@" a251 "<" (itoa acad__assertNo) ">"))) (if (=  acad__assertNo kHereAiciHeirIciAqui) (alert (strcat "Hi! eBreakPoint kHereAiciHeirIciAqui=" (itoa kHereAiciHeirIciAqui)))) 
erlsp)
;;;Inf: Here is starting routine

(deFun C:Q2() ;_ASSERT_OK
  (setq;|a5405|;
	 acad__assertNo (if_int acad__assertNo 0)) (if (and  (<  acad__assertNo (- 10)) (/= const_error nil)) (setq;|a5469|;
	 kHereAiciHeirIciAqui (- acad__assertNo))) (setq;|a5487|;
	 acad__assertNo 0) 
 (winmain_pp_utmcoosmall_run)
)
(prompt "\nCommand.com : Q2[enter]\n")
(defun winmain_pp_utmcoosmall_run( / );_ASSERT_OK
  

;------------------------;$
  (setq utmx1 451602.19)
;------------------------
;------------------------;$
  (setq utmy1 4519076.99)
;------------------------
;------------------------;$
  (setq zoneutm1 "33n")
;------------------------
;------------------------Stdcall "pp_utm_watermocasin "
  (setq _ax (pp_utm_watermocasin utmx1 utmy1 zoneutm1))
;------------------------
;------------------------;$
  (setq arxgate _ax)
;------------------------
;------------------------;$
  (setq utmx2 (getreal "\nenter utmx2: "))
;------------------------
;------------------------;$
  (setq utmy2 (getreal "enter utmy2: "))
;------------------------
;------------------------;$
  (setq zoneutm2 "32n")
;------------------------
;------------------------Stdcall "pp_utm_watermocasin "
  (setq _ax (pp_utm_watermocasin utmx2 utmy2 zoneutm2))
;------------------------
;------------------------;$
  (setq arxgate (strcat arxgate _ax "\n"))
;------------------------
;------------------------;$
  (setq utmx3 (getreal "\nenter utmx3: "))
;------------------------
;------------------------;$
  (setq utmy3 (getreal "enter utmy3: "))
;------------------------
;------------------------;$
  (setq zoneutm3 "31n")
;------------------------
;------------------------Stdcall "pp_utm_watermocasin "
  (setq _ax (pp_utm_watermocasin utmx3 utmy3 zoneutm3))
;------------------------
;------------------------;$
  (setq arxgate (strcat arxgate _ax "\n"))
;------------------------
;------------------------;$
  (setq utmx3 (getreal "\nenter utmx3: "))
;------------------------
;------------------------;$
  (setq utmy3 (getreal "enter utmy3: "))
;------------------------
;------------------------;$
  (setq zoneutm3 (getstring "enter utm zone(e.g. ~31a~): "))
;------------------------
;------------------------Stdcall "pp_utm_watermocasin "
  (setq _ax (pp_utm_watermocasin utmx3 utmy3 zoneutm3))
;------------------------
;------------------------;$
  (setq arxgate (strcat arxgate _ax "\n"))
;------------------------
;------------------------;$
  (alert arxgate)
;------------------------
;;;rem:----------------------------------------------------------------------
  (princ "\nThe End")  
rr)
;;;rem:---User Labels----cad_apages----- 
;;;rem:---(call_copy_source)----cad_apages----- 

;;  .--/|
;;/,`\
;;` | \____\\
;; _(      ) \
;; \-\~~~_|\  \
;;    \ `   \  `
;;    `     `
;Lib:free



(defun pp_utm_watermocasin(utmX utmY utmZone / rr latitude longitude len isnorthhemisphere diflat diflon c_sa c_sb e2 e2cuadrada c x y s v a1 a2 j2 j4 j6 alfa beta gama bm epsi eps nab senoheps delt tao zone $db $ol jcxz)
  (setq;|a20456|;
	 $db "\nError"
	 latitude 0
	 longitude 0
	 len (php_strlen utmZone)) (if (>  len 1) (progn  (setq;|a20632|;
	 isNorthHemisphere (substr utmZone len 1)
	 diflat (- 0.00066286966871111111111111111111111111)
	 diflon (- 0.0003868060578)
	 utmZone (substr utmZone 1 (- len 1))) (setq;|a20754|;
	 c_sa 6378137.000000) (setq;|a20770|;
	 c_sb 6356752.314245) (setq;|a20786|;
	 e2 (/ (math_pow (- (math_pow c_sa 2) (math_pow c_sb 2)) 0.5) c_sb)) (setq;|a20862|;
	 e2cuadrada (math_pow e2 2)) (setq;|a20894|;
	 c (/ (math_pow c_sa 2) c_sb)) (setq;|a20932|;
	 x (- utmX 500000)) (setq;|a20954|;
	 isNorthHemisphere (if (>  isNorthHemisphere "N") T nil)) (setq;|a20990|;
	 y (if isNorthHemisphere utmY (- utmY 10000000))) (setq;|a21024|;
	 zone (atoi utmZone)) (setq;|a21048|;
	 s (- (* zone 6.0) 183.0)) (setq;|a21076|;
	 lat (/ y (* 6366197.724 0.9996))) (setq;|a21104|;
	 v (* (/ c (math_pow (+ 1 (* e2cuadrada (math_pow (cos lat) 2))) 0.5)) 0.9996)) (setq;|a21178|;
	 a (/ x v)) (setq;|a21200|;
	 a1 (sin (* 2 lat))) (setq;|a21224|;
	 a2 (* a1 (math_pow (cos lat) 2))) (setq;|a21264|;
	 j2 (+ lat (/ a1 2.0))) (setq;|a21292|;
	 j4 (/ (+ (* 3 j2) a2) 4.0)) (setq;|a21326|;
	 j6 (/ (+ (* 5 j4) (* a2 (math_pow (cos lat) 2))) 3.0)) (setq;|a21384|;
	 alfa (* (/ 3.0 4.0) e2cuadrada)) (setq;|a21412|;
	 beta (* (/ 5.0 3.0) (math_pow alfa 2))) (setq;|a21456|;
	 gama (* (/ 35.0 27.0) (math_pow alfa 3))) (setq;|a21500|;
	 bm (* 0.9996 c (- (+ (- lat (* alfa j2)) (* beta j4)) (* gama j6)))) (setq;|a21564|;
	 b (/ (- y bm) v)) (setq;|a21592|;
	 epsi (* (/ (* e2cuadrada (math_pow a 2)) 2.0) (math_pow (cos lat) 2))) (setq;|a21660|;
	 eps (* a (- 1 (/ epsi 3.0)))) (setq;|a21694|;
	 nab (+ (* b (- 1 epsi)) lat)) (setq;|a21728|;
	 senoheps (/ (- (math_exp eps) (math_exp (- eps))) 2.0)) (setq;|a21774|;
	 delt (atan (/ senoheps (cos nab)))) (setq;|a21800|;
	 tao (atan (/ (* (cos delt) (sin nab)) (cos nab)))) (setq;|a21836|;
	 longitude (+ (* (/ delt Math_PI) 180) s)) (setq;|a21870|;
	 latitude (* (/ (+ lat (* (- (+ 1 (* e2cuadrada (math_pow (cos lat) 2))) (* (/ 3.0 2.0) e2cuadrada (sin lat) (cos lat) (- tao lat))) (- tao lat))) Math_PI) 180.0)) (setq;|a21992|;
	 rr (strcat "\nLatitud: " (rtos latitude 2 12) "\tLongitud: " (rtos longitude 2 12))) (setq;|a22088|;
	 $db rr) (str_princ $db))) (princ "\nAll done okai") 
$db)
;Lib:free


(defun php_strlen(a111 / rr es) 
  (if (=  a111 nil) (setq;|a23620|;
	 rr (- 1)) (progn  (setq;|a23646|;
	 es (if (=  (type a111) (quote SYM)) (eval a111) a111)
	 rr (if (=  (type es) (quote STR)) (strlen es) (- 2)))))  
rr)
;Lib:free

(defun math_exp(a295 / rr) (asserte "A295")
  (setq;|a24505|;
	 rr (if (numberp a295) a295 nil)
	 rr (if (=  rr nil) (rxtrace "a295errA<>RTREAL") (exp rr))) 
rr)
;Lib:free


(defun math_piA ( / rr)
  (setq;|a25057|;
	 rr (* 4.0 (atan 1.0))
	 math_pi rr) 
rr)
(setq math_pi (math_piA))
(setq math.pi math_pi)
;Lib:free


(defun math_pow(a294 la37 / rr qq ww) (asserte "A294")
  (setq;|a26841|;
	 rr nil
	 qq (if (numberp a294) a294 nil)
	 ww (if (numberp la37) la37 nil)) (if (=  qq nil) (setq;|a26947|;
	 rr (rxtrace "a294errA<>RTREAL")) (if (=  ww nil) (setq;|a26989|;
	 rr (rxtrace "a294errL<>RTREAL")) (if (and  qq ww) (setq;|a27027|;
	 rr (expt qq ww))))) 
rr)
;Lib:free


(defun str_princ2(a101 / rr ad gq)  (asserte "A101")
  (if (=  nil (dfn_var_isstr con_princeax)) (setq;|a28904|;
	 con_princeax "")) (if (dfn_var_isstr a101) (setq;|a28944|;
	 qq (list (princ a101) (princ con_princeax))) (progn  (if (=  (car a101) nil) (setq;|a29026|;
	 gq (textscr)
	 a101 (cdr a101))) (foreach ad a101 (princ ad) (princ con_princeax)))) 

nil)
(defun str_princ(a101 / ) (str_princ2 a101))
;Lib:free


(defun rxtrace(ai_error / $rr)
  (alert ai_error) 
1)
;Lib:free


;Lib:free

;;;Out:("...".is STR maxim 512characters)
;;;rem:    ;(nil.else)
;;;Lib:free
(Defun dfn_var_isstr (a094 / rr) ;_ASSERT_OK
  (setq;|a32316|;
	 rr (if (=  (type a094) (quote STR)) a094 nil)) 
rr)
;Lib:free
 ;;;{$R -cad_amain_eof T229@:032512run="devcinfo.exe
(prompt "\ncommand.com: GEO2[enter]\n")
;;;rem:End of file
;;;</-cad_amain_eof>

210423123111_idx0008.jpg

Message 7 of 8
hak_vz
in reply to: diagodose2009

@diagodose2009 

When you have such long source code, it is better to attach it as a file.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 8 of 8
CodeDing
in reply to: bahman.jf.68

@bahman.jf.68 ,

 

If your drawing is Geo-Located, this is all you need to GET a Lat/Long (well, this returns Long, then, Lat.. because of X / Y reasons):

;; Entmake's an arbitrary GeoMarker
;; returns - ename, of marker
(defun GeoMarker ( / )
  (entmakex '((0 . "POSITIONMARKER") (100 . "AcDbEntity") (100 . "AcDbGeoPositionMarker") (90 . 0) (10 0.0 0.0 0.0) (40 . 1.0)
             (1 . "") (40 . 0.5) (290 . 0) (280 . 0) (290 . 1) (101 . "Embedded Object") (100 . "AcDbEntity") (100 . "AcDbMText")
             (10 0.1 0.1 0.0) (40 . 1.0) (1 . "") (210 0.0 0.0 1.0) (11 1.0 0.0 0.0) (42 . 9761.9) (43 . 6666.67)))
);defun

;; Gets Lat & Long of a GeoMarker
;; e - ename, of GeoPositionMarker
;; returns - point, as (Long Lat 0.0) of geo marker
(defun GeoMarkerLL (e / )
  (setq e (vlax-ename->vla-object e))
  (mapcar
    'atof
    (list (vla-get-Longitude e) (vla-get-Latitude e))
  );mapcar
);defun

;; Turns a point into (long lat) point ..ONLY useable if dwg is Geo-Located.
;; pt - point, 
;; returns - point, as (Long Lat) ...since longitudes represent "x" values & Latitudes represent "y" values
(defun PT->LL (pt / e prec return)
  (if (and pt
           (setq e (GeoMarker)))
    (progn
      (setpropertyvalue e "Position/X" (car pt))
      (setpropertyvalue e "Position/Y" (cadr pt))
      (setq prec (getvar 'LUPREC))
      (setvar 'LUPREC 8)
      (setq return (GeoMarkerLL e))
      (setvar 'LUPREC prec)
      (entdel e)
      return
    );progn
  );if
);defun

(defun c:TEST ( / pt ll)
  (if (and (not (eq "" (getvar 'CGEOCS)))
           (setq pt (getpoint))
           (setq ll (PT->LL pt)))
    (alert
      (strcat
        "Your Long/Lat point is: "
        "(" (rtos (car ll) 2 5) " " (rtos (cadr ll) 2 5) ")"
      );strccat
    );alert
  ;else
    (alert "Is drawing Geo-Located? Was a point selected? Try again.")
  );if
  (princ)
);defun

 

CodeDing_0-1619185706012.png

 

Best,

~DD

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost