14 namespace GeographicLib {
20 const char* spaces =
" \t\n\v\f\r,";
21 for (string::size_type pos0 = 0, pos1; pos0 != string::npos;) {
22 pos1 = s.find_first_not_of(spaces, pos0);
23 if (pos1 == string::npos)
25 pos0 = s.find_first_of(spaces, pos1);
26 sa.push_back(s.substr(pos1, pos0 == string::npos ? pos0 : pos0 - pos1));
30 MGRS::Reverse(sa[0], _zone, _northp, _easting, _northing, prec, centerp);
32 _lat, _long, _gamma, _k);
33 }
else if (sa.size() == 2) {
36 _zone, _northp, _easting, _northing, _gamma, _k);
37 }
else if (sa.size() == 3) {
38 unsigned zoneind, coordind;
39 if (sa[0].size() > 0 && isalpha(sa[0][sa[0].size() - 1])) {
42 }
else if (sa[2].size() > 0 && isalpha(sa[2][sa[2].size() - 1])) {
47 +
" of the form UTM/UPS Zone + Hemisphere"
48 +
" (ex: 38n, 09s, n)");
50 for (
unsigned i = 0; i < 2; ++i)
51 (i ? _northing : _easting) =
DMS::Decode(sa[coordind + i]);
53 _lat, _long, _gamma, _k);
56 throw GeographicErr(
"Coordinate requires 1, 2, or 3 elements");
63 os << fixed << setprecision(prec);
64 real a = swaplatlong ? _long : _lat;
65 real b = swaplatlong ? _lat : _long;
81 return DMS::Encode(swaplatlong ? _long : _lat,
unsigned(prec),
83 " " +
DMS::Encode(swaplatlong ? _lat : _long,
unsigned(prec),
89 prec = max(-1, min(6, prec) + 5);
91 MGRS::Forward(_zone, _northp, _easting, _northing, _lat, prec, mgrs);
97 prec = max(-1, min(6, prec) + 5);
99 MGRS::Forward(_alt_zone, _northp, _alt_easting, _alt_northing, _lat, prec,
104 void GeoCoords::UTMUPSString(
int zone,
bool northp,
105 real easting,
real northing,
int prec,
106 bool abbrev, std::string& utm) {
112 os <<
" " << setprecision(max(0, prec)) << easting / scale;
113 if (prec < 0 && abs(easting / scale) >
real(0.5))
114 os << setw(-prec) << 0;
118 os <<
" " << setprecision(max(0, prec)) << northing / scale;
119 if (prec < 0 && abs(northing / scale) >
real(0.5))
120 os << setw(-prec) << 0;
128 UTMUPSString(_zone, _northp, _easting, _northing, prec, abbrev, utm);
137 _zone, northp, e, n, z);
139 UTMUPSString(_zone, northp, e, n, prec, abbrev, utm);
145 UTMUPSString(_alt_zone, _northp, _alt_easting, _alt_northing, prec,
155 _alt_zone, northp, e, n, z);
157 UTMUPSString(_alt_zone, northp, e, n, prec, abbrev, utm);
161 void GeoCoords::FixHemisphere() {
162 if (_lat == 0 || (_northp && _lat >= 0) || (!_northp && _lat < 0) ||
170 throw GeographicErr(
"Hemisphere mixup");