21 const char* spaces =
" \t\n\v\f\r,";
22 for (string::size_type pos0 = 0, pos1; pos0 != string::npos;) {
23 pos1 = s.find_first_not_of(spaces, pos0);
24 if (pos1 == string::npos)
26 pos0 = s.find_first_of(spaces, pos1);
27 sa.push_back(s.substr(pos1, pos0 == string::npos ? pos0 : pos0 - pos1));
31 MGRS::Reverse(sa[0], _zone, _northp, _easting, _northing, prec, centerp);
33 _lat, _long, _gamma, _k);
34 }
else if (sa.size() == 2) {
38 _zone, _northp, _easting, _northing, _gamma, _k);
39 }
else if (sa.size() == 3) {
40 unsigned zoneind, coordind;
41 if (sa[0].size() > 0 && isalpha(sa[0][sa[0].size() - 1])) {
44 }
else if (sa[2].size() > 0 && isalpha(sa[2][sa[2].size() - 1])) {
49 +
" of the form UTM/UPS Zone + Hemisphere" 50 +
" (ex: 38n, 09s, n)");
52 for (
unsigned i = 0; i < 2; ++i)
53 (i ? _northing : _easting) = Utility::val<real>(sa[coordind + i]);
55 _lat, _long, _gamma, _k);
58 throw GeographicErr(
"Coordinate requires 1, 2, or 3 elements");
65 os << fixed << setprecision(prec);
66 real a = longfirst ? _long : _lat;
67 real b = longfirst ? _lat : _long;
83 return DMS::Encode(longfirst ? _long : _lat,
unsigned(prec),
85 " " +
DMS::Encode(longfirst ? _lat : _long,
unsigned(prec),
91 prec = max(-1, min(6, prec) + 5);
93 MGRS::Forward(_zone, _northp, _easting, _northing, _lat, prec, mgrs);
99 prec = max(-1, min(6, prec) + 5);
101 MGRS::Forward(_alt_zone, _northp, _alt_easting, _alt_northing, _lat, prec,
106 void GeoCoords::UTMUPSString(
int zone,
bool northp,
107 real easting, real northing,
int prec,
108 bool abbrev, std::string& utm) {
111 real scale = prec < 0 ? pow(
real(10), -prec) :
real(1);
114 os <<
" " <<
Utility::str(easting / scale, max(0, prec));
115 if (prec < 0 && abs(easting / scale) >
real(0.5))
116 os << setw(-prec) << 0;
120 os <<
" " <<
Utility::str(northing / scale, max(0, prec));
121 if (prec < 0 && abs(northing / scale) >
real(0.5))
122 os << setw(-prec) << 0;
130 UTMUPSString(_zone, _northp, _easting, _northing, prec, abbrev, utm);
139 _zone, northp, e, n, z);
141 UTMUPSString(_zone, northp, e, n, prec, abbrev, utm);
147 UTMUPSString(_alt_zone, _northp, _alt_easting, _alt_northing, prec,
157 _alt_zone, northp, e, n, z);
159 UTMUPSString(_alt_zone, northp, e, n, prec, abbrev, utm);
163 void GeoCoords::FixHemisphere() {
164 if (_lat == 0 || (_northp && _lat >= 0) || (!_northp && _lat < 0) ||
static T AngNormalize(T x)
static std::string EncodeZone(int zone, bool northp, bool abbrev=true)
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
static bool isfinite(T x)
std::string UTMUPSRepresentation(int prec=0, bool abbrev=true) const
static void Transfer(int zonein, bool northpin, real xin, real yin, int zoneout, bool northpout, real &xout, real &yout, int &zone)
Header for GeographicLib::GeoCoords class.
Header for GeographicLib::MGRS class.
static int extra_digits()
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)
std::string MGRSRepresentation(int prec=0) const
static std::string Encode(real angle, component trailing, unsigned prec, flag ind=NONE, char dmssep=char(0))
Namespace for GeographicLib.
static void DecodeZone(const std::string &zonestr, int &zone, bool &northp)
static std::string str(T x, int p=-1)
std::string AltMGRSRepresentation(int prec=0) const
std::string AltUTMUPSRepresentation(int prec=0, bool abbrev=true) const
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool longfirst=false)
static void Reverse(int zone, bool northp, real x, real y, real &lat, real &lon, real &gamma, real &k, bool mgrslimits=false)
static void Reverse(const std::string &mgrs, int &zone, bool &northp, real &x, real &y, int &prec, bool centerp=true)
std::string GeoRepresentation(int prec=0, bool longfirst=false) const
Exception handling for GeographicLib.
std::string DMSRepresentation(int prec=0, bool longfirst=false, char dmssep=char(0)) const
static Math::real UTMShift()
void Reset(const std::string &s, bool centerp=true, bool longfirst=false)
static void Forward(int zone, bool northp, real x, real y, int prec, std::string &mgrs)
Header for GeographicLib::DMS class.