Converted by latitude

Source: Internet
Author: User
Tags cos pow sin
#region//latitude and longitude transfer of Mercator
static double m_pi = Math.PI;
Transfer of Mercator by latitude
Longitude (Lon), Latitude (LAT)
Public double[] Lonlat2mercator (double lat, double lon)
{
double[] xy = new DOUBLE[2];
Double x = Lon *20037508.342789/180;
Double y = Math.Log (Math.tan (90+lat) *m_pi/360))/(m_pi/180);
y = y *20037508.34789/180;
Xy[0] = x;
Xy[1] = y;
return XY;
}
Mercator Transfer latitude
Public double[] Mercator2lonlat (double mercatorx,double mercatory)
{
double[] xy = new DOUBLE[2];
Double x = mercatorx/20037508.34*180;
Double y = mercatory/20037508.34*180;
Y= 180/m_pi* (2*math.atan (Math.exp (y*m_pi/180))-M_PI/2);
Xy[0] = x;
Xy[1] = y;
return XY;
}
#endregion
#region latitude and longitude transfer geodetic coordinates


Double pi = Math.PI;


Double sm_a = 6378137.0;


Double sm_b = 6356752.314;


Double utmscalefactor = 0.9996;


Public double[] LATLONTOUTM (double lat, double lon)
{
Double zone = Math.floor ((lon + 180.0)/6) + 1;


Double cm = Utmcentralmeridian (zone);


double[] xy = new DOUBLE[2];


Maplatlontoxy (lat/180.0 * pi, lon/180 * pi, CM, out xy);


/* Adjust easting and northing for UTM system. */


Xy[0] = xy[0] * utmscalefactor + 500000.0;


if (Lon > 120.0)
{
Xy[0] + + 530000;
}


XY[1] = xy[1] * utmscalefactor;


if (Xy[1] < 0.0)
{
XY[1] = xy[1] + 10000000.0;
}


return new double[] {xy[0], xy[1], zone};
}


Public double Utmcentralmeridian (double zone)
{
Double Cmeridian;


Double deg = -183.0 + (Zone * 6.0);


Cmeridian = deg/180.0 * PI;


return Cmeridian;
}


internal void Maplatlontoxy (double phi, double lambda, double lambda0, out double[] xy)
{
Double N, nu2, EP2, T, T2, L;


Double L3coef, L4coef, L5coef, L6coef, L7coef, L8coef;


Double tmp;


/* Precalculate EP2 * *


EP2 = (Math.pow (sm_a, 2.0)-Math.pow (Sm_b, 2.0))/Math.pow (Sm_b, 2.0);


/* Precalculate NU2 * *


NU2 = EP2 * Math.pow (Math.Cos (PHI), 2.0);


/* Precalculate N * *


N = Math.pow (sm_a, 2.0)/(Sm_b * MATH.SQRT (1 + nu2));


/* Precalculate T * *


t = Math.tan (PHI);


t2 = t * t;


TMP = (T2 * T2 * T2)-Math.pow (T, 6.0);


/* precalculate L * *


L = lambda-lambda0;


/* Precalculate coefficients for l**n in the equations below


So a normal human being can read the expressions for easting


and northing


--l**1 and l**2 have coefficients of 1.0 * *


L3coef = 1.0-t2 + nu2;


L4coef = 5.0-t2 + 9 * NU2 + 4.0 * (NU2 * nu2);


L5coef = 5.0-18.0 * t2 + (t2 * T2) + 14.0 * nu2-58.0 * T2 * NU2;


L6coef = 61.0-58.0 * t2 + (t2 * T2) + 270.0 * nu2-330.0 * T2 * NU2;


L7coef = 61.0-479.0 * T2 + 179.0 * (T2 * T2)-(T2 * T2 * T2);


L8coef = 1385.0-3111.0 * T2 + 543.0 * (T2 * T2)-(T2 * T2 * T2);


/* Calculate easting (x) * *


XY = new DOUBLE[2];


XY[0] = N * Math.Cos (PHI) * L


+ (n/6.0 * MATH.POW (Math.Cos (PHI), 3.0) * L3coef * MATH.POW (L, 3.0))


+ (n/120.0 * MATH.POW (Math.Cos (PHI), 5.0) * L5coef * MATH.POW (L, 5.0))


+ (n/5040.0 * MATH.POW (Math.Cos (PHI), 7.0) * L7coef * MATH.POW (L, 7.0));


/* Calculate northing (y) * *


XY[1] = Arclengthofmeridian (PHI)


+ (t/2.0 * N * MATH.POW (Math.Cos (PHI), 2.0) * MATH.POW (L, 2.0))


+ (t/24.0 * N * MATH.POW (Math.Cos (PHI), 4.0) * L4coef * MATH.POW (L, 4.0))


+ (t/720.0 * N * MATH.POW (Math.Cos (PHI), 6.0) * L6coef * MATH.POW (L, 6.0))


+ (t/40320.0 * N * MATH.POW (Math.Cos (PHI), 8.0) * L8coef * MATH.POW (L, 8.0));


Return
}


Internal Double Arclengthofmeridian (double phi)
{


Double alpha, Beta, Gamma, delta, Epsilon, N;


Double result;


/* precalculate N * *


n = (sm_a-sm_b)/(Sm_a + sm_b);


/* Precalculate Alpha * *


Alpha = ((Sm_a + sm_b)/2.0)


* (1.0 + (Math.pow (n, 2.0)/4.0) + (MATH.POW (n, 4.0)/64.0));


* Precalculate Beta *


Beta = ( -3.0 * n/2.0) + (9.0 * MATH.POW (n, 3.0)/16.0)


+ ( -3.0 * MATH.POW (n, 5.0)/32.0);


* Precalculate Gamma *


Gamma = (15.0 * MATH.POW (n, 2.0)/16.0)


+ ( -15.0 * MATH.POW (n, 4.0)/32.0);


* Precalculate Delta * *


Delta = ( -35.0 * MATH.POW (n, 3.0)/48.0)


+ (105.0 * MATH.POW (n, 5.0)/256.0);


/* Precalculate Epsilon * *


Epsilon = (315.0 * MATH.POW (n, 4.0)/512.0);


/* Now calculate the sum of the series and return * * *


result = Alpha


* (phi + (Beta * Math.sin (2.0 * phi))


+ (Gamma * Math.sin (4.0 * phi))


+ (Delta * Math.sin (6.0 * phi))


+ (Epsilon * Math.sin (8.0 * phi));


return result;


}


#endregion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.