18# pragma warning (disable: 5055)
25 const int UTMUPS::falseeasting_[] =
26 { MGRS::upseasting_ * MGRS::tile_, MGRS::upseasting_ * MGRS::tile_,
27 MGRS::utmeasting_ * MGRS::tile_, MGRS::utmeasting_ * MGRS::tile_ };
28 const int UTMUPS::falsenorthing_[] =
29 { MGRS::upseasting_ * MGRS::tile_, MGRS::upseasting_ * MGRS::tile_,
30 MGRS::maxutmSrow_ * MGRS::tile_, MGRS::minutmNrow_ * MGRS::tile_ };
31 const int UTMUPS::mineasting_[] =
32 { MGRS::minupsSind_ * MGRS::tile_, MGRS::minupsNind_ * MGRS::tile_,
33 MGRS::minutmcol_ * MGRS::tile_, MGRS::minutmcol_ * MGRS::tile_ };
34 const int UTMUPS::maxeasting_[] =
35 { MGRS::maxupsSind_ * MGRS::tile_, MGRS::maxupsNind_ * MGRS::tile_,
36 MGRS::maxutmcol_ * MGRS::tile_, MGRS::maxutmcol_ * MGRS::tile_ };
37 const int UTMUPS::minnorthing_[] =
38 { MGRS::minupsSind_ * MGRS::tile_, MGRS::minupsNind_ * MGRS::tile_,
39 MGRS::minutmSrow_ * MGRS::tile_,
40 (MGRS::minutmNrow_ + MGRS::minutmSrow_ - MGRS::maxutmSrow_)
42 const int UTMUPS::maxnorthing_[] =
43 { MGRS::maxupsSind_ * MGRS::tile_, MGRS::maxupsNind_ * MGRS::tile_,
44 (MGRS::maxutmSrow_ + MGRS::maxutmNrow_ - MGRS::minutmNrow_) *
46 MGRS::maxutmNrow_ * MGRS::tile_ };
54 if (isnan(lat) || isnan(lon))
56 if (setzone ==
UTM || (lat >= -80 && lat < 84)) {
59 int zone = (ilon + 186)/6;
60 int band = MGRS::LatitudeBand(lat);
61 if (band == 7 && zone == 31 && ilon >= 3)
63 else if (band == 9 && ilon >= 0 && ilon < 42)
64 zone = 2 * ((ilon + 183)/12) + 1;
71 int& zone,
bool& northp, real& x, real& y,
73 int setzone,
bool mgrslimits) {
76 +
"d not in [-" + to_string(
Math::qd)
77 +
"d, " + to_string(
Math::qd) +
"d]");
78 bool northp1 = !(signbit(lat));
86 real x1, y1, gamma1, k1;
87 bool utmp = zone1 !=
UPS;
90 lon0 = CentralMeridian(zone1),
96 +
"d more than 60d from center of UTM zone "
103 +
"d more than 20d from "
104 + (northp1 ?
"N" :
"S") +
" pole");
107 int ind = (utmp ? 2 : 0) + (northp1 ? 1 : 0);
108 x1 += falseeasting_[ind];
109 y1 += falsenorthing_[ind];
110 if (! CheckCoords(zone1 !=
UPS, northp1, x1, y1, mgrslimits,
false) )
113 +
" out of legal range for "
125 real& lat, real& lon, real& gamma, real& k,
128 if (zone ==
INVALID || isnan(x) || isnan(y)) {
134 +
" not in range [0, 60]");
135 bool utmp = zone !=
UPS;
136 CheckCoords(utmp, northp, x, y, mgrslimits);
137 int ind = (utmp ? 2 : 0) + (northp ? 1 : 0);
138 x -= falseeasting_[ind];
139 y -= falsenorthing_[ind];
142 x, y, lat, lon, gamma, k);
147 bool UTMUPS::CheckCoords(
bool utmp,
bool northp,
real x,
real y,
148 bool mgrslimits,
bool throwp) {
151 real slop = mgrslimits ? 0 : MGRS::tile_;
152 int ind = (utmp ? 2 : 0) + (northp ? 1 : 0);
153 if (x < mineasting_[ind] - slop || x > maxeasting_[ind] + slop) {
154 if (!throwp)
return false;
156 + (mgrslimits ?
"MGRS/" :
"")
157 + (utmp ?
"UTM" :
"UPS") +
" range for "
158 + (northp ?
"N" :
"S" ) +
" hemisphere ["
164 if (y < minnorthing_[ind] - slop || y > maxnorthing_[ind] + slop) {
165 if (!throwp)
return false;
166 throw GeographicErr(
"Northing " +
Utility::str(y/1000) +
"km not in "
167 + (mgrslimits ?
"MGRS/" :
"")
168 + (utmp ?
"UTM" :
"UPS") +
" range for "
169 + (northp ?
"N" :
"S" ) +
" hemisphere ["
179 int zoneout,
bool northpout, real& xout, real& yout,
181 bool northp = northpin;
182 if (zonein != zoneout) {
192 if (zone1 == 0 && northp != northpout)
194 (
"Attempt to transfer UPS coordinates between hemispheres");
199 if (zoneout == 0 && northp != northpout)
201 (
"Attempt to transfer UPS coordinates between hemispheres");
206 if (northp != northpout)
208 yout += (northpout ? -1 : 1) * MGRS::utmNshift_;
214 unsigned zlen = unsigned(zonestr.size());
219 throw GeographicErr(
"More than 7 characters in zone specification "
222 const char* c = zonestr.c_str();
224 int zone1 = strtol(c, &q, 10);
231 ", use just the hemisphere for UPS");
234 +
" not in range [1, 60]");
235 else if (!isdigit(zonestr[0]))
239 throw GeographicErr(
"More than 2 digits use to specify zone "
242 string hemi(zonestr, q - c);
243 for (string::iterator p = hemi.begin(); p != hemi.end(); ++p)
244 *p = char(tolower(*p));
245 if (q == c && (hemi ==
"inv" || hemi ==
"invalid")) {
250 bool northp1 = hemi ==
"north" || hemi ==
"n";
251 if (!(northp1 || hemi ==
"south" || hemi ==
"s"))
252 throw GeographicErr(
string(
"Illegal hemisphere ") + hemi +
" in "
253 + zonestr +
", specify north or south");
260 return string(abbrev ?
"inv" :
"invalid");
263 +
" not in range [0, 60]");
266 os << setfill(
'0') << setw(2) << zone;
268 os << (northp ?
'n' :
's');
270 os << (northp ?
"north" :
"south");
276 if (epsg >= epsg01N && epsg <= epsg60N) {
279 }
else if (epsg == epsgN) {
282 }
else if (epsg >= epsg01S && epsg <= epsg60S) {
284 }
else if (epsg == epsgS) {
297 if (epsg >= 0 && northp)
298 epsg += epsgN - epsgS;
GeographicLib::Math::real real
Header for GeographicLib::MGRS class.
Header for GeographicLib::PolarStereographic class.
Header for GeographicLib::TransverseMercator class.
Header for GeographicLib::UTMUPS class.
Header for GeographicLib::Utility class.
Exception handling for GeographicLib.
static T AngNormalize(T x)
static T AngDiff(T x, T y, T &e)
@ hd
degrees per half turn
@ qd
degrees per quarter turn
void Reverse(bool northp, real x, real y, real &lat, real &lon, real &gamma, real &k) const
static const PolarStereographic & UPS()
void Forward(bool northp, real lat, real lon, real &x, real &y, real &gamma, real &k) const
void Reverse(real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
static const TransverseMercator & UTM()
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 int StandardZone(real lat, real lon, int setzone=STANDARD)
static std::string EncodeZone(int zone, bool northp, bool abbrev=true)
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)
static void DecodeEPSG(int epsg, int &zone, bool &northp)
static void Reverse(int zone, bool northp, real x, real y, real &lat, real &lon, real &gamma, real &k, bool mgrslimits=false)
static Math::real UTMShift()
static void Transfer(int zonein, bool northpin, real xin, real yin, int zoneout, bool northpout, real &xout, real &yout, int &zone)
static void DecodeZone(const std::string &zonestr, int &zone, bool &northp)
static std::string str(T x, int p=-1)
Namespace for GeographicLib.