分享

大地坐标系(wgs84)转UTM

 快乐一箩筐 2012-07-10

到现成的c#代码。。。
干脆自己根据一个网站上的js写了一个。

001 class Program
002 {
003     static void Main(string[] args)
004     {
005         double[] utm = LatLonToUTM(30.65156708, 103.6880587);
006     }
007  
008  
009     static double pi = Math.PI;
010  
011     static double sm_a = 6378137.0;
012     static double sm_b = 6356752.314;
013     //static double sm_EccSquared = 6.69437999013e-03;
014  
015     static double UTMScaleFactor = 0.9996;
016     //得到的结果是:x坐标,y坐标,区域编号
017     public static double[] LatLonToUTM (double lat, double lon)
018     {
019         double zone = Math.Floor((lon + 180.0) / 6) + 1;
020  
021         double cm = UTMCentralMeridian(zone);
022  
023         double[] xy = new double[2];
024  
025         MapLatLonToXY(lat / 180.0 * pi, lon / 180 * pi, cm, out xy);
026  
027         /* Adjust easting and northing for UTM system. */
028         xy[0] = xy[0] * UTMScaleFactor + 500000.0;
029         xy[1] = xy[1] * UTMScaleFactor;
030         if (xy[1] < 0.0)
031         {
032             xy[1] = xy[1] + 10000000.0;
033         }
034  
035         return new double[] { xy[0], xy[1], zone };
036     }
037  
038     public static double UTMCentralMeridian (double zone)
039     {
040         double cmeridian;
041  
042         double deg = -183.0 + (zone * 6.0);
043  
044         cmeridian = deg / 180.0 * pi;
045   
046         return cmeridian;
047     }
048  
049     internal static void MapLatLonToXY (double phi, double lambda, double lambda0, out double[] xy)
050     {
051         double N, nu2, ep2, t, t2, l;
052         double l3coef, l4coef, l5coef, l6coef, l7coef, l8coef;
053         double tmp;
054  
055         /* Precalculate ep2 */
056         ep2 = (Math.Pow(sm_a, 2.0) - Math.Pow(sm_b, 2.0)) / Math.Pow(sm_b, 2.0);
057   
058         /* Precalculate nu2 */
059         nu2 = ep2 * Math.Pow(Math.Cos(phi), 2.0);
060   
061         /* Precalculate N */
062         N = Math.Pow(sm_a, 2.0) / (sm_b * Math.Sqrt(1 + nu2));
063   
064         /* Precalculate t */
065         t = Math.Tan (phi);
066         t2 = t * t;
067         tmp = (t2 * t2 * t2) - Math.Pow (t, 6.0);
068  
069         /* Precalculate l */
070         l = lambda - lambda0;
071   
072         /* Precalculate coefficients for l**n in the equations below
073            so a normal human being can read the expressions for easting
074            and northing
075            -- l**1 and l**2 have coefficients of 1.0 */
076         l3coef = 1.0 - t2 + nu2;
077   
078         l4coef = 5.0 - t2 + 9 * nu2 + 4.0 * (nu2 * nu2);
079   
080         l5coef = 5.0 - 18.0 * t2 + (t2 * t2) + 14.0 * nu2
081             - 58.0 * t2 * nu2;
082   
083         l6coef = 61.0 - 58.0 * t2 + (t2 * t2) + 270.0 * nu2
084             - 330.0 * t2 * nu2;
085   
086         l7coef = 61.0 - 479.0 * t2 + 179.0 * (t2 * t2) - (t2 * t2 * t2);
087   
088         l8coef = 1385.0 - 3111.0 * t2 + 543.0 * (t2 * t2) - (t2 * t2 * t2);
089  
090         /* Calculate easting (x) */
091  
092         xy = new double[2];
093         xy[0] = N * Math.Cos (phi) * l
094             + (N / 6.0 * Math.Pow (Math.Cos (phi), 3.0) * l3coef * Math.Pow (l, 3.0))
095             + (N / 120.0 * Math.Pow(Math.Cos(phi), 5.0) * l5coef * Math.Pow(l, 5.0))
096             + (N / 5040.0 * Math.Pow(Math.Cos(phi), 7.0) * l7coef * Math.Pow(l, 7.0));
097   
098         /* Calculate northing (y) */
099         xy[1] = ArcLengthOfMeridian (phi)
100             + (t / 2.0 * N * Math.Pow(Math.Cos(phi), 2.0) * Math.Pow(l, 2.0))
101             + (t / 24.0 * N * Math.Pow(Math.Cos(phi), 4.0) * l4coef * Math.Pow(l, 4.0))
102             + (t / 720.0 * N * Math.Pow(Math.Cos(phi), 6.0) * l6coef * Math.Pow(l, 6.0))
103             + (t / 40320.0 * N * Math.Pow(Math.Cos(phi), 8.0) * l8coef * Math.Pow(l, 8.0));
104   
105         return;
106     }
107  
108     internal static double ArcLengthOfMeridian(double phi)
109     {
110         double alpha, beta, gamma, delta, epsilon, n;
111         double result;
112  
113         /* Precalculate n */
114         n = (sm_a - sm_b) / (sm_a + sm_b);
115  
116         /* Precalculate alpha */
117         alpha = ((sm_a + sm_b) / 2.0)
118            * (1.0 + (Math.Pow(n, 2.0) / 4.0) + (Math.Pow(n, 4.0) / 64.0));
119  
120         /* Precalculate beta */
121         beta = (-3.0 * n / 2.0) + (9.0 * Math.Pow(n, 3.0) / 16.0)
122            + (-3.0 * Math.Pow(n, 5.0) / 32.0);
123  
124         /* Precalculate gamma */
125         gamma = (15.0 * Math.Pow(n, 2.0) / 16.0)
126             + (-15.0 * Math.Pow(n, 4.0) / 32.0);
127   
128         /* Precalculate delta */
129         delta = (-35.0 * Math.Pow(n, 3.0) / 48.0)
130             + (105.0 * Math.Pow(n, 5.0) / 256.0);
131   
132         /* Precalculate epsilon */
133         epsilon = (315.0 * Math.Pow(n, 4.0) / 512.0);
134   
135         /* Now calculate the sum of the series and return */
136         result = alpha
137             * (phi + (beta * Math.Sin (2.0 * phi))
138                 + (gamma * Math.Sin(4.0 * phi))
139                 + (delta * Math.Sin(6.0 * phi))
140                 + (epsilon * Math.Sin(8.0 * phi)));
141  
142         return result;
143     }
144  
145 }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多