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)) {
51 int ilon = int(floor(fmod(lon,
real(360))));
56 int zone = (ilon + 186)/6;
57 int band = MGRS::LatitudeBand(lat);
58 if (band == 7 && zone == 31 && ilon >= 3)
60 else if (band == 9 && ilon >= 0 && ilon < 42)
61 zone = 2 * ((ilon + 183)/12) + 1;
68 int& zone,
bool& northp, real& x, real& y,
70 int setzone,
bool mgrslimits) {
73 +
"d not in [-90d, 90d]");
74 bool northp1 = lat >= 0;
75 int zone1 = StandardZone(lat, lon, setzone);
76 if (zone1 == INVALID) {
82 real x1, y1, gamma1, k1;
83 bool utmp = zone1 != UPS;
86 lon0 = CentralMeridian(zone1),
88 dlon = abs(dlon - 360 * floor((dlon + 180)/360));
93 +
"d more than 60d from center of UTM zone " 100 +
"d more than 20d from " 101 + (northp1 ?
"N" :
"S") +
" pole");
104 int ind = (utmp ? 2 : 0) + (northp1 ? 1 : 0);
105 x1 += falseeasting_[ind];
106 y1 += falsenorthing_[ind];
107 if (! CheckCoords(zone1 != UPS, northp1, x1, y1, mgrslimits,
false) )
110 +
" out of legal range for " 122 real& lat, real& lon, real& gamma, real& k,
128 if (!(zone >= MINZONE && zone <= MAXZONE))
130 +
" not in range [0, 60]");
131 bool utmp = zone != UPS;
132 CheckCoords(utmp, northp, x, y, mgrslimits);
133 int ind = (utmp ? 2 : 0) + (northp ? 1 : 0);
134 x -= falseeasting_[ind];
135 y -= falsenorthing_[ind];
138 x, y, lat, lon, gamma, k);
143 bool UTMUPS::CheckCoords(
bool utmp,
bool northp,
real x,
real y,
144 bool mgrslimits,
bool throwp) {
147 real slop = mgrslimits ? 0 : MGRS::tile_;
148 int ind = (utmp ? 2 : 0) + (northp ? 1 : 0);
149 if (x < mineasting_[ind] - slop || x > maxeasting_[ind] + slop) {
150 if (!throwp)
return false;
152 + (mgrslimits ?
"MGRS/" :
"")
153 + (utmp ?
"UTM" :
"UPS") +
" range for " 154 + (northp ?
"N" :
"S" ) +
" hemisphere [" 160 if (y < minnorthing_[ind] - slop || y > maxnorthing_[ind] + slop) {
161 if (!throwp)
return false;
162 throw GeographicErr(
"Northing " +
Utility::str(y/1000) +
"km not in " 163 + (mgrslimits ?
"MGRS/" :
"")
164 + (utmp ?
"UTM" :
"UPS") +
" range for " 165 + (northp ?
"N" :
"S" ) +
" hemisphere [" 175 int zoneout,
bool northpout, real& xout, real& yout,
177 bool northp = northpin;
178 if (zonein != zoneout) {
188 if (zone1 == 0 && northp != northpout)
190 (
"Attempt to transfer UPS coordinates between hemispheres");
195 if (zoneout == 0 && northp != northpout)
197 (
"Attempt to transfer UPS coordinates between hemispheres");
202 if (northp != northpout)
204 yout += (northpout ? -1 : 1) * MGRS::utmNshift_;
210 unsigned zlen = unsigned(zonestr.size());
215 throw GeographicErr(
"More than 7 characters in zone specification " 218 const char* c = zonestr.c_str();
220 int zone1 = strtol(c, &q, 10);
227 ", use just the hemisphere for UPS");
228 }
else if (!(zone1 >= MINUTMZONE && zone1 <= MAXUTMZONE))
230 +
" not in range [1, 60]");
231 else if (!isdigit(zonestr[0]))
235 throw GeographicErr(
"More than 2 digits use to specify zone " 238 string hemi(zonestr, q - c);
239 for (std::string::iterator p = hemi.begin(); p != hemi.end(); ++p)
240 *p =
char(std::tolower(*p));
241 if (q == c && (hemi ==
"inv" || hemi ==
"invalid")) {
246 bool northp1 = hemi ==
"north" || hemi ==
"n";
247 if (!(northp1 || hemi ==
"south" || hemi ==
"s"))
248 throw GeographicErr(
string(
"Illegal hemisphere ") + hemi +
" in " 249 + zonestr +
", specify north or south");
256 return string(abbrev ?
"inv" :
"invalid");
257 if (!(zone >= MINZONE && zone <= MAXZONE))
259 +
" not in range [0, 60]");
262 os << setfill(
'0') << setw(2) << zone;
264 os << (northp ?
'n' :
's');
266 os << (northp ?
"north" :
"south");
272 if (epsg >= epsg01N && epsg <= epsg60N) {
273 zone = (epsg - epsg01N) + MINUTMZONE;
275 }
else if (epsg == epsgN) {
278 }
else if (epsg >= epsg01S && epsg <= epsg60S) {
279 zone = (epsg - epsg01S) + MINUTMZONE;
280 }
else if (epsg == epsgS) {
291 else if (zone >= MINUTMZONE && zone <= MAXUTMZONE)
292 epsg = (zone - MINUTMZONE) + epsg01S;
293 if (epsg >= 0 && northp)
294 epsg += epsgN - epsgS;
static std::string EncodeZone(int zone, bool northp, bool abbrev=true)
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
Header for GeographicLib::UTMUPS class.
static void Transfer(int zonein, bool northpin, real xin, real yin, int zoneout, bool northpout, real &xout, real &yout, int &zone)
static void DecodeEPSG(int epsg, int &zone, bool &northp)
static const TransverseMercator & UTM()
void Reverse(bool northp, real x, real y, real &lat, real &lon, real &gamma, real &k) const
Header for GeographicLib::TransverseMercator class.
Header for GeographicLib::MGRS class.
static void Forward(real lat, real lon, int &zone, bool &northp, real &x, real &y, real &gamma, real &k, int setzone=STANDARD, bool mgrslimits=false)
void Forward(real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
static int EncodeEPSG(int zone, bool northp)
static const PolarStereographic & UPS()
Namespace for GeographicLib.
static void DecodeZone(const std::string &zonestr, int &zone, bool &northp)
static std::string str(T x, int p=-1)
static void Reverse(int zone, bool northp, real x, real y, real &lat, real &lon, real &gamma, real &k, bool mgrslimits=false)
Exception handling for GeographicLib.
static Math::real UTMShift()
Header for GeographicLib::PolarStereographic class.
void Reverse(real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
static int StandardZone(real lat, real lon, int setzone=STANDARD)
void Forward(bool northp, real lat, real lon, real &x, real &y, real &gamma, real &k) const