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");
static std::string EncodeZone(int zone, bool northp, bool abbrev=true)
std::string GeoRepresentation(int prec=0, bool swaplatlong=false) const
GeographicLib::Math::real real
static bool isfinite(T x)
static void Transfer(int zonein, bool northpin, real xin, real yin, int zoneout, bool northpout, real &xout, real &yout, int &zone)
std::string AltUTMUPSRepresentation(int prec=0, bool abbrev=true) const
std::string DMSRepresentation(int prec=0, bool swaplatlong=false, char dmssep=char(0)) const
Header for GeographicLib::GeoCoords class.
Header for GeographicLib::MGRS class.
static int extra_digits()
void Reset(const std::string &s, bool centerp=true, bool swaplatlong=false)
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 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 swaplatlong=false)
static Math::real Decode(const std::string &dms, flag &ind)
std::string AltMGRSRepresentation(int prec=0) const
Namespace for GeographicLib.
static void DecodeZone(const std::string &zonestr, 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 void Reverse(const std::string &mgrs, int &zone, bool &northp, real &x, real &y, int &prec, bool centerp=true)
Exception handling for GeographicLib.
std::string MGRSRepresentation(int prec=0) const
static Math::real UTMShift()
static void Forward(int zone, bool northp, real x, real y, int prec, std::string &mgrs)
std::string UTMUPSRepresentation(int prec=0, bool abbrev=true) const
Header for GeographicLib::DMS class.