23 void LLtoUTM(
int ReferenceEllipsoid,
const double Lat,
const double Long,
24 double &UTMNorthing,
double &UTMEasting,
char* UTMZone) {
31 double a = ellipsoid[ReferenceEllipsoid].EquatorialRadius;
32 double eccSquared = ellipsoid[ReferenceEllipsoid].eccentricitySquared;
36 double eccPrimeSquared;
40 double LongTemp = (Long + 180) -
int((Long + 180) / 360)*360 - 180;
43 double LongRad = LongTemp*
deg2rad;
47 ZoneNumber =
int((LongTemp + 180) / 6) + 1;
49 if (Lat >= 56.0 && Lat < 64.0 && LongTemp >= 3.0 && LongTemp < 12.0)
53 if (Lat >= 72.0 && Lat < 84.0) {
54 if (LongTemp >= 0.0 && LongTemp < 9.0) ZoneNumber = 31;
55 else if (LongTemp >= 9.0 && LongTemp < 21.0) ZoneNumber = 33;
56 else if (LongTemp >= 21.0 && LongTemp < 33.0) ZoneNumber = 35;
57 else if (LongTemp >= 33.0 && LongTemp < 42.0) ZoneNumber = 37;
59 LongOrigin = (ZoneNumber - 1)*6 - 180 + 3;
60 LongOriginRad = LongOrigin *
deg2rad;
65 eccPrimeSquared = (eccSquared) / (1 - eccSquared);
67 N =
a / sqrt(1 - eccSquared * sin(LatRad) * sin(LatRad));
68 T = tan(LatRad) * tan(LatRad);
69 C = eccPrimeSquared * cos(LatRad) * cos(LatRad);
70 A = cos(LatRad)*(LongRad - LongOriginRad);
72 M =
a * ((1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256) * LatRad
73 - (3 * eccSquared / 8 + 3 * eccSquared * eccSquared / 32 + 45 * eccSquared * eccSquared * eccSquared / 1024) * sin(2 * LatRad)
74 + (15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024) * sin(4 * LatRad)
75 - (35 * eccSquared * eccSquared * eccSquared / 3072) * sin(6 * LatRad));
77 UTMEasting = (
double) (k0 *
N * (A + (1 - T +
C) * A * A * A / 6
78 + (5 - 18 * T + T * T + 72 *
C - 58 * eccPrimeSquared) * A * A * A * A * A / 120)
81 UTMNorthing = (
double) (k0 * (
M +
N * tan(LatRad)*(A * A / 2 + (5 - T + 9 *
C + 4 *
C *
C) * A * A * A * A / 24
82 + (61 - 58 * T + T * T + 600 *
C - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720)));
84 UTMNorthing += 10000000.0;
91 char LetterDesignator;
93 if ((84 >= Lat) && (Lat >= 72)) LetterDesignator =
'X';
94 else if ((72 > Lat) && (Lat >= 64)) LetterDesignator =
'W';
95 else if ((64 > Lat) && (Lat >= 56)) LetterDesignator =
'V';
96 else if ((56 > Lat) && (Lat >= 48)) LetterDesignator =
'U';
97 else if ((48 > Lat) && (Lat >= 40)) LetterDesignator =
'T';
98 else if ((40 > Lat) && (Lat >= 32)) LetterDesignator =
'S';
99 else if ((32 > Lat) && (Lat >= 24)) LetterDesignator =
'R';
100 else if ((24 > Lat) && (Lat >= 16)) LetterDesignator =
'Q';
101 else if ((16 > Lat) && (Lat >= 8)) LetterDesignator =
'P';
102 else if ((8 > Lat) && (Lat >= 0)) LetterDesignator =
'N';
103 else if ((0 > Lat) && (Lat >= -8)) LetterDesignator =
'M';
104 else if ((-8 > Lat) && (Lat >= -16)) LetterDesignator =
'L';
105 else if ((-16 > Lat) && (Lat >= -24)) LetterDesignator =
'K';
106 else if ((-24 > Lat) && (Lat >= -32)) LetterDesignator =
'J';
107 else if ((-32 > Lat) && (Lat >= -40)) LetterDesignator =
'H';
108 else if ((-40 > Lat) && (Lat >= -48)) LetterDesignator =
'G';
109 else if ((-48 > Lat) && (Lat >= -56)) LetterDesignator =
'F';
110 else if ((-56 > Lat) && (Lat >= -64)) LetterDesignator =
'E';
111 else if ((-64 > Lat) && (Lat >= -72)) LetterDesignator =
'D';
112 else if ((-72 > Lat) && (Lat >= -80)) LetterDesignator =
'C';
113 else LetterDesignator =
'Z';
115 return LetterDesignator;
118 void UTMtoLL(
int ReferenceEllipsoid,
const double UTMNorthing,
const double UTMEasting,
const char* UTMZone,
119 double& Lat,
double& Long) {
127 double a = ellipsoid[ReferenceEllipsoid].EquatorialRadius;
128 double eccSquared = ellipsoid[ReferenceEllipsoid].eccentricitySquared;
129 double eccPrimeSquared;
130 double e1 = (1 - sqrt(1 - eccSquared)) / (1 + sqrt(1 - eccSquared));
131 double N1, T1,
C1, R1, D,
M;
140 x = UTMEasting - 500000.0;
143 ZoneNumber = strtoul(UTMZone, &ZoneLetter, 10);
153 if ((*ZoneLetter -
'N') < 0) {
157 LongOrigin = (ZoneNumber - 1)*6 - 180 + 3;
159 eccPrimeSquared = (eccSquared) / (1 - eccSquared);
162 mu =
M / (
a * (1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256));
164 phi1Rad =
mu + (3 * e1 / 2 - 27 * e1 * e1 * e1 / 32) * sin(2 *
mu)
165 + (21 * e1 * e1 / 16 - 55 * e1 * e1 * e1 * e1 / 32) * sin(4 *
mu)
166 +(151 * e1 * e1 * e1 / 96) * sin(6 *
mu);
169 N1 =
a / sqrt(1 - eccSquared * sin(phi1Rad) * sin(phi1Rad));
170 T1 = tan(phi1Rad) * tan(phi1Rad);
171 C1 = eccPrimeSquared * cos(phi1Rad) * cos(phi1Rad);
172 R1 =
a * (1 - eccSquared) / pow(1 - eccSquared * sin(phi1Rad) * sin(phi1Rad), 1.5);
175 Lat = phi1Rad - (N1 * tan(phi1Rad) / R1)*(D * D / 2 - (5 + 3 * T1 + 10 *
C1 - 4 *
C1 *
C1 - 9 * eccPrimeSquared) * D * D * D * D / 24
176 + (61 + 90 * T1 + 298 *
C1 + 45 * T1 * T1 - 252 * eccPrimeSquared - 3 *
C1 *
C1) * D * D * D * D * D * D / 720);
179 Long = (D - (1 + 2 * T1 +
C1) * D * D * D / 6 + (5 - 2 *
C1 + 28 * T1 - 3 *
C1 *
C1 + 8 * eccPrimeSquared + 24 * T1 * T1)
180 * D * D * D * D * D / 120) / cos(phi1Rad);
181 Long = LongOrigin + Long *
rad2deg;