20 const int UTMUPS::falseeasting_[] =
21 { MGRS::upseasting_ * MGRS::tile_, MGRS::upseasting_ * MGRS::tile_,
22 MGRS::utmeasting_ * MGRS::tile_, MGRS::utmeasting_ * MGRS::tile_ };
23 const int UTMUPS::falsenorthing_[] =
24 { MGRS::upseasting_ * MGRS::tile_, MGRS::upseasting_ * MGRS::tile_,
25 MGRS::maxutmSrow_ * MGRS::tile_, MGRS::minutmNrow_ * MGRS::tile_ };
26 const int UTMUPS::mineasting_[] =
27 { MGRS::minupsSind_ * MGRS::tile_, MGRS::minupsNind_ * MGRS::tile_,
28 MGRS::minutmcol_ * MGRS::tile_, MGRS::minutmcol_ * MGRS::tile_ };
29 const int UTMUPS::maxeasting_[] =
30 { MGRS::maxupsSind_ * MGRS::tile_, MGRS::maxupsNind_ * MGRS::tile_,
31 MGRS::maxutmcol_ * MGRS::tile_, MGRS::maxutmcol_ * MGRS::tile_ };
32 const int UTMUPS::minnorthing_[] =
33 { MGRS::minupsSind_ * MGRS::tile_, MGRS::minupsNind_ * MGRS::tile_,
34 MGRS::minutmSrow_ * MGRS::tile_,
35 (MGRS::minutmNrow_ + MGRS::minutmSrow_ - MGRS::maxutmSrow_)
37 const int UTMUPS::maxnorthing_[] =
38 { MGRS::maxupsSind_ * MGRS::tile_, MGRS::maxupsNind_ * MGRS::tile_,
39 (MGRS::maxutmSrow_ + MGRS::maxutmNrow_ - MGRS::minutmNrow_) *
41 MGRS::maxutmNrow_ * MGRS::tile_ };
44 if (!(setzone >= MINPSEUDOZONE && setzone <= MAXZONE))
46 if (setzone >= MINZONE || setzone == INVALID)
50 if (setzone == UTM || (lat >= -80 && lat < 84)) {
52 if (ilon == 180) ilon = -180;
53 int zone = (ilon + 186)/6;
54 int band = MGRS::LatitudeBand(lat);
55 if (band == 7 && zone == 31 && ilon >= 3)
57 else if (band == 9 && ilon >= 0 && ilon < 42)
58 zone = 2 * ((ilon + 183)/12) + 1;
65 int& zone,
bool& northp, real& x, real& y,
67 int setzone,
bool mgrslimits) {
70 +
"d not in [-90d, 90d]");
71 bool northp1 = lat >= 0;
72 int zone1 = StandardZone(lat, lon, setzone);
73 if (zone1 == INVALID) {
79 real x1, y1, gamma1, k1;
80 bool utmp = zone1 != UPS;
83 lon0 = CentralMeridian(zone1),
85 dlon = abs(dlon - 360 * floor((dlon + 180)/360));
90 +
"d more than 60d from center of UTM zone "
97 +
"d more than 20d from "
98 + (northp1 ?
"N" :
"S") +
" pole");
101 int ind = (utmp ? 2 : 0) + (northp1 ? 1 : 0);
102 x1 += falseeasting_[ind];
103 y1 += falsenorthing_[ind];
104 if (! CheckCoords(zone1 != UPS, northp1, x1, y1, mgrslimits,
false) )
107 +
" out of legal range for "
119 real& lat, real& lon, real& gamma, real& k,
125 if (!(zone >= MINZONE && zone <= MAXZONE))
127 +
" not in range [0, 60]");
128 bool utmp = zone != UPS;
129 CheckCoords(utmp, northp, x, y, mgrslimits);
130 int ind = (utmp ? 2 : 0) + (northp ? 1 : 0);
131 x -= falseeasting_[ind];
132 y -= falsenorthing_[ind];
135 x, y, lat, lon, gamma, k);
140 bool UTMUPS::CheckCoords(
bool utmp,
bool northp,
real x,
real y,
141 bool mgrslimits,
bool throwp) {
144 real slop = mgrslimits ? 0 : MGRS::tile_;
145 int ind = (utmp ? 2 : 0) + (northp ? 1 : 0);
146 if (x < mineasting_[ind] - slop || x > maxeasting_[ind] + slop) {
147 if (!throwp)
return false;
149 + (mgrslimits ?
"MGRS/" :
"")
150 + (utmp ?
"UTM" :
"UPS") +
" range for "
151 + (northp ?
"N" :
"S" ) +
" hemisphere ["
157 if (y < minnorthing_[ind] - slop || y > maxnorthing_[ind] + slop) {
158 if (!throwp)
return false;
159 throw GeographicErr(
"Northing " +
Utility::str(y/1000) +
"km not in "
160 + (mgrslimits ?
"MGRS/" :
"")
161 + (utmp ?
"UTM" :
"UPS") +
" range for "
162 + (northp ?
"N" :
"S" ) +
" hemisphere ["
172 int zoneout,
bool northpout, real& xout, real& yout,
174 bool northp = northpin;
175 if (zonein != zoneout) {
185 if (zone1 == 0 && northp != northpout)
187 (
"Attempt to transfer UPS coordinates between hemispheres");
192 if (zoneout == 0 && northp != northpout)
194 (
"Attempt to transfer UPS coordinates between hemispheres");
199 if (northp != northpout)
201 yout += (northpout ? -1 : 1) * MGRS::utmNshift_;
207 unsigned zlen = unsigned(zonestr.size());
212 throw GeographicErr(
"More than 7 characters in zone specification "
215 const char* c = zonestr.c_str();
217 int zone1 = strtol(c, &q, 10);
224 ", use just the hemisphere for UPS");
225 }
else if (!(zone1 >= MINUTMZONE && zone1 <= MAXUTMZONE))
227 +
" not in range [1, 60]");
228 else if (!isdigit(zonestr[0]))
232 throw GeographicErr(
"More than 2 digits use to specify zone "
235 string hemi(zonestr, q - c);
236 for (std::string::iterator p = hemi.begin(); p != hemi.end(); ++p)
237 *p =
char(std::tolower(*p));
238 if (q == c && (hemi ==
"inv" || hemi ==
"invalid")) {
243 bool northp1 = hemi ==
"north" || hemi ==
"n";
244 if (!(northp1 || hemi ==
"south" || hemi ==
"s"))
245 throw GeographicErr(
string(
"Illegal hemisphere ") + hemi +
" in "
246 + zonestr +
", specify north or south");
253 return string(abbrev ?
"inv" :
"invalid");
254 if (!(zone >= MINZONE && zone <= MAXZONE))
256 +
" not in range [0, 60]");
259 os << setfill(
'0') << setw(2) << zone;
261 os << (northp ?
'n' :
's');
263 os << (northp ?
"north" :
"south");
269 if (epsg >= epsg01N && epsg <= epsg60N) {
270 zone = (epsg - epsg01N) + MINUTMZONE;
272 }
else if (epsg == epsgN) {
275 }
else if (epsg >= epsg01S && epsg <= epsg60S) {
276 zone = (epsg - epsg01S) + MINUTMZONE;
277 }
else if (epsg == epsgS) {
288 else if (zone >= MINUTMZONE && zone <= MAXUTMZONE)
289 epsg = (zone - MINUTMZONE) + epsg01S;
290 if (epsg >= 0 && northp)
291 epsg += epsgN - epsgS;