Tuesday, May 27, 2008

Lat Long to UTM

Hi All,

here is the AutoLisp code to convert the Geographic coordinates into UTM projection system.

(Defun LL2UTM (xval yval)
(setq UTM nil)
(setq statA 6378137.0)
(setq statB 6356752.314)
(setq statF 0.003352811)
(setq statIF 298.2572236)
(setq statRM 6367435.68)
(setq statK0 0.9996)
(setq statE 0.081819191)
(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 (+ 30 (Fix (/ xval 6))))
(setq ZoneCM (- (* 6 Zone) 183))
(setq DeltaLon (/ (* (- xval ZoneCM) 3600) 10000))
(setq LatRad (/ (* yval 3.14159265358979) 180))
(setq LongRad (/ (* xval 3.14159265358979) 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 8))) ) (+ (* 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))
UTM
)
Please let us know if you need any help

Regards,

GIS Programmers.

1 comment:

Ray Moran said...

I am after something similar to your Lisp routine to convert Lat/Long to UTM,, but what I want to do is convert UTM to Lat/Long.
THis is to enable a dwg file to be prepped to convert to KML.
The UTM Zones I use is for Australia.