20 const int UTMUPS::falseeasting_[4] =
21 { MGRS::upseasting_ * MGRS::tile_, MGRS::upseasting_ * MGRS::tile_,
22 MGRS::utmeasting_ * MGRS::tile_, MGRS::utmeasting_ * MGRS::tile_ };
23 const int UTMUPS::falsenorthing_[4] =
24 { MGRS::upseasting_ * MGRS::tile_, MGRS::upseasting_ * MGRS::tile_,
25 MGRS::maxutmSrow_ * MGRS::tile_, MGRS::minutmNrow_ * MGRS::tile_ };
26 const int UTMUPS::mineasting_[4] =
27 { MGRS::minupsSind_ * MGRS::tile_, MGRS::minupsNind_ * MGRS::tile_,
28 MGRS::minutmcol_ * MGRS::tile_, MGRS::minutmcol_ * MGRS::tile_ };
29 const int UTMUPS::maxeasting_[4] =
30 { MGRS::maxupsSind_ * MGRS::tile_, MGRS::maxupsNind_ * MGRS::tile_,
31 MGRS::maxutmcol_ * MGRS::tile_, MGRS::maxutmcol_ * MGRS::tile_ };
32 const int UTMUPS::minnorthing_[4] =
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_[4] =
38 { MGRS::maxupsSind_ * MGRS::tile_, MGRS::maxupsNind_ * MGRS::tile_,
39 (MGRS::maxutmSrow_ + MGRS::maxutmNrow_ - MGRS::minutmNrow_) * MGRS::tile_,
40 MGRS::maxutmNrow_ * MGRS::tile_ };
43 if (!(setzone >= MINPSEUDOZONE && setzone <= MAXZONE))
45 if (setzone >= MINZONE || setzone == INVALID)
49 if (setzone == UTM || (lat >= -80 && lat < 84)) {
50 int ilon = int(floor(fmod(lon,
real(360))));
55 int zone = (ilon + 186)/6;
56 int band = MGRS::LatitudeBand(lat);
57 if (band == 7 && zone == 31 && ilon >= 3)
59 else if (band == 9 && ilon >= 0 && ilon < 42)
60 zone = 2 * ((ilon + 183)/12) + 1;
67 int& zone,
bool& northp, real& x, real& y,
69 int setzone,
bool mgrslimits) {
72 +
"d not in [-90d, 90d]");
73 bool northp1 = lat >= 0;
74 int zone1 = StandardZone(lat, lon, setzone);
75 if (zone1 == INVALID) {
81 real x1, y1, gamma1, k1;
82 bool utmp = zone1 != UPS;
85 lon0 = CentralMeridian(zone1),
87 dlon = abs(dlon - 360 * floor((dlon + 180)/360));
92 +
"d more than 60d from center of UTM zone "
99 +
"d more than 20d from "
100 + (northp1 ?
"N" :
"S") +
" pole");
103 int ind = (utmp ? 2 : 0) + (northp1 ? 1 : 0);
104 x1 += falseeasting_[ind];
105 y1 += falsenorthing_[ind];
106 if (! CheckCoords(zone1 != UPS, northp1, x1, y1, mgrslimits,
false) )
109 +
" out of legal range for "
120 real& lat, real& lon, real& gamma, real& k,
126 if (!(zone >= MINZONE && zone <= MAXZONE))
128 +
" not in range [0, 60]");
129 bool utmp = zone != UPS;
130 CheckCoords(utmp, northp, x, y, mgrslimits);
131 int ind = (utmp ? 2 : 0) + (northp ? 1 : 0);
132 x -= falseeasting_[ind];
133 y -= falsenorthing_[ind];
136 x, y, lat, lon, gamma, k);
141 bool UTMUPS::CheckCoords(
bool utmp,
bool northp,
real x,
real y,
142 bool mgrslimits,
bool throwp) {
145 real slop = mgrslimits ? 0 : MGRS::tile_;
146 int ind = (utmp ? 2 : 0) + (northp ? 1 : 0);
147 if (x < mineasting_[ind] - slop || x > maxeasting_[ind] + slop) {
148 if (!throwp)
return false;
150 + (mgrslimits ?
"MGRS/" :
"")
151 + (utmp ?
"UTM" :
"UPS") +
" range for "
152 + (northp ?
"N" :
"S" ) +
" hemisphere ["
158 if (y < minnorthing_[ind] - slop || y > maxnorthing_[ind] + slop) {
159 if (!throwp)
return false;
160 throw GeographicErr(
"Northing " +
Utility::str(y/1000) +
"km not in "
161 + (mgrslimits ?
"MGRS/" :
"")
162 + (utmp ?
"UTM" :
"UPS") +
" range for "
163 + (northp ?
"N" :
"S" ) +
" hemisphere ["
173 int zoneout,
bool northpout, real& xout, real& yout,
175 bool northp = northpin;
176 if (zonein != zoneout) {
186 if (zone1 == 0 && northp != northpout)
188 (
"Attempt to transfer UPS coordinates between hemispheres");
193 if (zoneout == 0 && northp != northpout)
195 (
"Attempt to transfer UPS coordinates between hemispheres");
200 if (northp != northpout)
202 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.substr(q - c);
236 transform(hemi.begin(), hemi.end(), hemi.begin(), (int(*)(int))tolower);
237 if (q == c && (hemi ==
"inv" || hemi ==
"invalid")) {
242 bool northp1 = hemi ==
"north" || hemi ==
"n";
243 if (!(northp1 || hemi ==
"south" || hemi ==
"s"))
244 throw GeographicErr(
string(
"Illegal hemisphere ") + hemi +
" in "
245 + zonestr +
", specify north or south");
252 return string(abbrev ?
"inv" :
"invalid");
253 if (!(zone >= MINZONE && zone <= MAXZONE))
255 +
" not in range [0, 60]");
258 os << setfill(
'0') << setw(2) << zone;
260 os << (northp ?
'n' :
's');
262 os << (northp ?
"north" :
"south");
268 if (epsg >= epsg01N && epsg <= epsg60N) {
269 zone = (epsg - epsg01N) + MINUTMZONE;
271 }
else if (epsg == epsgN) {
274 }
else if (epsg >= epsg01S && epsg <= epsg60S) {
275 zone = (epsg - epsg01S) + MINUTMZONE;
276 }
else if (epsg == epsgS) {
287 else if (zone >= MINUTMZONE && zone <= MAXUTMZONE)
288 epsg = (zone - MINUTMZONE) + epsg01S;
289 if (epsg >= 0 && northp)
290 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)
void Forward(real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
static const TransverseMercator & UTM()
Header for GeographicLib::TransverseMercator class.
void Forward(bool northp, real lat, real lon, real &x, real &y, real &gamma, real &k) const
Header for GeographicLib::MGRS class.
void Reverse(bool northp, real x, real y, real &lat, real &lon, real &gamma, real &k) const
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 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)
void Reverse(real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
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.
static int StandardZone(real lat, real lon, int setzone=STANDARD)