到现成的c#代码。。。 干脆自己根据一个网站上的js写了一个。
003 |
static void Main( string [] args) |
005 |
double [] utm = LatLonToUTM(30.65156708, 103.6880587); |
009 |
static double pi = Math.PI; |
011 |
static double sm_a = 6378137.0; |
012 |
static double sm_b = 6356752.314; |
015 |
static double UTMScaleFactor = 0.9996; |
017 |
public static double [] LatLonToUTM ( double lat, double lon) |
019 |
double zone = Math.Floor((lon + 180.0) / 6) + 1; |
021 |
double cm = UTMCentralMeridian(zone); |
023 |
double [] xy = new double [2]; |
025 |
MapLatLonToXY(lat / 180.0 * pi, lon / 180 * pi, cm, out xy); |
028 |
xy[0] = xy[0] * UTMScaleFactor + 500000.0; |
029 |
xy[1] = xy[1] * UTMScaleFactor; |
032 |
xy[1] = xy[1] + 10000000.0; |
035 |
return new double [] { xy[0], xy[1], zone }; |
038 |
public static double UTMCentralMeridian ( double zone) |
042 |
double deg = -183.0 + (zone * 6.0); |
044 |
cmeridian = deg / 180.0 * pi; |
049 |
internal static void MapLatLonToXY ( double phi, double lambda, double lambda0, out double [] xy) |
051 |
double N, nu2, ep2, t, t2, l; |
052 |
double l3coef, l4coef, l5coef, l6coef, l7coef, l8coef; |
056 |
ep2 = (Math.Pow(sm_a, 2.0) - Math.Pow(sm_b, 2.0)) / Math.Pow(sm_b, 2.0); |
059 |
nu2 = ep2 * Math.Pow(Math.Cos(phi), 2.0); |
062 |
N = Math.Pow(sm_a, 2.0) / (sm_b * Math.Sqrt(1 + nu2)); |
067 |
tmp = (t2 * t2 * t2) - Math.Pow (t, 6.0); |
070 |
l = lambda - lambda0; |
076 |
l3coef = 1.0 - t2 + nu2; |
078 |
l4coef = 5.0 - t2 + 9 * nu2 + 4.0 * (nu2 * nu2); |
080 |
l5coef = 5.0 - 18.0 * t2 + (t2 * t2) + 14.0 * nu2 |
083 |
l6coef = 61.0 - 58.0 * t2 + (t2 * t2) + 270.0 * nu2 |
086 |
l7coef = 61.0 - 479.0 * t2 + 179.0 * (t2 * t2) - (t2 * t2 * t2); |
088 |
l8coef = 1385.0 - 3111.0 * t2 + 543.0 * (t2 * t2) - (t2 * t2 * t2); |
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)); |
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)); |
108 |
internal static double ArcLengthOfMeridian( double phi) |
110 |
double alpha, beta, gamma, delta, epsilon, n; |
114 |
n = (sm_a - sm_b) / (sm_a + sm_b); |
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)); |
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); |
125 |
gamma = (15.0 * Math.Pow(n, 2.0) / 16.0) |
126 |
+ (-15.0 * Math.Pow(n, 4.0) / 32.0); |
129 |
delta = (-35.0 * Math.Pow(n, 3.0) / 48.0) |
130 |
+ (105.0 * Math.Pow(n, 5.0) / 256.0); |
133 |
epsilon = (315.0 * Math.Pow(n, 4.0) / 512.0); |
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))); |
|