Jump to content

Need Help for this Lisp Routine. (Lat Long to UTM)


aaryan

Recommended Posts

Hi All,

My colleague found this code somewhere on the net to convert lat long to UTM in WGS84 datum. I am not an expert in writing AutoLISP but I tried and used this code and wrote routine to be worked with and convert a single coordinate (20.10° Lat(N) and 71.10° Long(E) to UTM, it works well the answer i got is (X:719569.724) (Y:2223930.682). But when i checked the same coordinate with other converters like Trimble and many on online, the answer is (X: 719569.731) (Y: 2223930.631). I actually want to fix this error but dont know how? Can anyone please help me out and tell me what am i missing?

Below is the lisp routine i have made using the code.

Sorry for the poor english.

Thanks in Advance to all of You.

(Defun C:DD2UTM	()
 (setq yval (getreal "\n Enter Lat Decimal Degrees: "))
 (setq xval (getreal "\n Enter Long Decimal Degrees: "))
 (setq UTM nil)
 (setq statA 6378137.0)
 (setq statB 6356752.3142)
 (setq statF 0.00335281066474748)
 (setq statIF 298.257223563)
 (setq statRM 6367435.68)
 (setq statK0 0.9996)
 (setq statE 0.081819190928906)
 (setq statE2 0.006739497)
 (setq statN 0.00167922)
 (setq ConstA0 6367449.14580084)
 (setq ConstB0 16038.4295531591)
 (setq ConstC0 16.8326133343344)
 (setq ConstD0 0.0219844042737573)
 (setq ConstE0 0.000312705217950448)
 (setq Sin1 0.00000484813681109536)
 (setq ConstE1SQ 0.006739496756587)
 (setq Zone (fix (+ 31 (/ xval 6))))
 (setq ZoneCM (- (* 6 Zone) 183))
 (setq DeltaLon (/ (* (- xval ZoneCM) 3600) 10000))
 (setq LatRad (/ (* yval 3.141592654) 180))
 (setq LongRad (/ (* xval 3.141592654) 180))
 (Setq	Curve1 (/ (* statA (- 1 (* statE statE)))
	  (/ (expt (- 1 (expt (* statE (Sin LatRad)) 2)) 2)
	     (sqrt (- 1 (expt (* statE (Sin LatRad)) 2)))
	  )
       )
 )
 (setq Curve2 (/ statA (sqrt (- 1 (expt (* statE (Sin LatRad)) 2)))))
 (setq	MeridArc (- (+ (* ConstA0 LatRad)
	       (* ConstC0 (sin (* LatRad 4)))
	       (* ConstE0 (sin (* LatRad ))
	    )
	    (+ (* ConstB0 (sin (* LatRad 2)))
	       (* ConstD0 (sin (* LatRad 6)))
	    )
	 )
 )
 (setq K1 (* MeridArc statK0))
 (setq	K2 (* Curve2
      (sin LatRad)
      (cos LatRad)
      (expt Sin1 2)
      statK0
      (/ 100000000 2)
   )
 )
 (setq	K3
 (* (/ (* (expt Sin1 4) Curve2 (sin LatRad) (expt (cos LatRad) 3))
       24
    )
    (+ (- 5 (expt (/ (sin LatRad) (cos LatRad)) 2))
       (* 9 ConstE1SQ (expt (cos LatRad) 2))
       (* 4 (expt ConstE1SQ 2) (expt (cos LatRad) 4))
    )
    statK0
    10000000000000000
 )
 )
 (setq K4 (* Curve2 (cos LatRad) Sin1 statK0 10000))
 (setq	K5 (* (expt (* Sin1 (cos LatRad)) 3)
      (/ Curve2 6)
      (+ (- 1 (expt (/ (sin LatRad) (cos LatRad)) 2))
	 (* ConstE1SQ (expt (cos LatRad) 2))
      )
      statK0
      1000000000000
   )
 )
 (setq
   RawNorth (+ K1 (* K2 DeltaLon DeltaLon) (* K3 (expt DeltaLon 4)))
 )
 (if (< RawNorth 0)
   (Setq Northing (+ 10000000 RawNorth))
   (Setq Northing RawNorth)
 )
 (setq Easting (+ 500000 (+ (* K4 DeltaLon) (* K5 (expt DeltaLon 3)))))
 (setq UTM (list Easting Northing))
 (setq utmx (rtos Easting 2 3))
 (setq utmy (rtos Northing 2 3))
 (princ (strcat "\n 		X:" utmx "\n 		Y:" utmy))
 (princ (strcat "\n 		zone:"
	 (itoa zone)
	 "\n 		CM:"
	 (rtos zonecm 2 0)
 )
 )
 (princ)
)

Link to comment
Share on other sites

  • 7 years later...
  • 2 years later...

(* ConstC0 (sin (* LatRad 4))) (* ConstE0 (sin (* LatRad ))   would you tell us what number cames after last LatRad in this expression because it was not writed

in you routine, but without it , this program not work well

  • Like 1
Link to comment
Share on other sites

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