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) {
37 _zone, _northp, _easting, _northing, _gamma, _k);
38 }
else if (sa.size() == 3) {
39 unsigned zoneind, coordind;
40 if (sa[0].size() > 0 && isalpha(sa[0][sa[0].size() - 1])) {
43 }
else if (sa[2].size() > 0 && isalpha(sa[2][sa[2].size() - 1])) {
48 +
" of the form UTM/UPS Zone + Hemisphere"
49 +
" (ex: 38n, 09s, n)");
51 for (
unsigned i = 0; i < 2; ++i)
52 (i ? _northing : _easting) = Utility::val<real>(sa[coordind + i]);
54 _lat, _long, _gamma, _k);
57 throw GeographicErr(
"Coordinate requires 1, 2, or 3 elements");
71 return DMS::Encode(longfirst ? _long : _lat,
unsigned(prec),
73 " " +
DMS::Encode(longfirst ? _lat : _long,
unsigned(prec),
79 prec = max(-1, min(6, prec) + 5);
81 MGRS::Forward(_zone, _northp, _easting, _northing, _lat, prec, mgrs);
87 prec = max(-1, min(6, prec) + 5);
89 MGRS::Forward(_alt_zone, _northp, _alt_easting, _alt_northing, _lat, prec,
94 void GeoCoords::UTMUPSString(
int zone,
bool northp,
95 real easting,
real northing,
int prec,
96 bool abbrev,
string& utm) {
102 if (isfinite(easting)) {
103 os <<
" " <<
Utility::str(easting / scale, max(0, prec));
104 if (prec < 0 && fabs(easting / scale) >
real(0.5))
105 os << setw(-prec) << 0;
108 if (isfinite(northing)) {
109 os <<
" " <<
Utility::str(northing / scale, max(0, prec));
110 if (prec < 0 && fabs(northing / scale) >
real(0.5))
111 os << setw(-prec) << 0;
119 UTMUPSString(_zone, _northp, _easting, _northing, prec, abbrev, utm);
128 _zone, northp, e, n, z);
130 UTMUPSString(_zone, northp, e, n, prec, abbrev, utm);
136 UTMUPSString(_alt_zone, _northp, _alt_easting, _alt_northing, prec,
146 _alt_zone, northp, e, n, z);
148 UTMUPSString(_alt_zone, northp, e, n, prec, abbrev, utm);
152 void GeoCoords::FixHemisphere() {
154 if (_lat == 0 || (_northp && _lat >= 0) || (!_northp && _lat < 0) ||
162 throw GeographicErr(
"Hemisphere mixup");
Header for GeographicLib::DMS class.
Header for GeographicLib::GeoCoords class.
GeographicLib::Math::real real
Header for GeographicLib::MGRS class.
Header for GeographicLib::Utility class.
static std::string Encode(real angle, component trailing, unsigned prec, flag ind=NONE, char dmssep=char(0))
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool longfirst=false)
std::string DMSRepresentation(int prec=0, bool longfirst=false, char dmssep=char(0)) const
void Reset(const std::string &s, bool centerp=true, bool longfirst=false)
std::string AltMGRSRepresentation(int prec=0) const
std::string UTMUPSRepresentation(int prec=0, bool abbrev=true) const
std::string GeoRepresentation(int prec=0, bool longfirst=false) const
std::string AltUTMUPSRepresentation(int prec=0, bool abbrev=true) const
std::string MGRSRepresentation(int prec=0) const
Exception handling for GeographicLib.
static void Reverse(const std::string &mgrs, int &zone, bool &northp, real &x, real &y, int &prec, bool centerp=true)
static void Forward(int zone, bool northp, real x, real y, int prec, std::string &mgrs)
static int extra_digits()
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 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.