15# pragma warning (disable: 5055)
22 const char*
const GARS::digits_ =
"0123456789";
23 const char*
const GARS::letters_ =
"ABCDEFGHJKLMNPQRSTUVWXYZ";
29 +
"d not in [-" + to_string(
Math::qd)
30 +
"d, " + to_string(
Math::qd) +
"d]");
31 if (isnan(lat) || isnan(lon)) {
37 if (lat ==
Math::qd) lat *= (1 - numeric_limits<real>::epsilon() / 2);
38 prec = max(0, min(
int(maxprec_), prec));
40 x = int(floor(lon * m_)) - lonorig_ * m_,
41 y = int(floor(lat * m_)) - latorig_ * m_,
42 ilon = x * mult1_ / m_,
43 ilat = y * mult1_ / m_;
44 x -= ilon * m_ / mult1_; y -= ilat * m_ / mult1_;
47 for (
int c = lonlen_; c--;) {
48 gars1[c] = digits_[ ilon % baselon_]; ilon /= baselon_;
50 for (
int c = latlen_; c--;) {
51 gars1[lonlen_ + c] = letters_[ilat % baselat_]; ilat /= baselat_;
54 ilon = x / mult3_; ilat = y / mult3_;
55 gars1[baselen_] = digits_[mult2_ * (mult2_ - 1 - ilat) + ilon + 1];
57 ilon = x % mult3_; ilat = y % mult3_;
58 gars1[baselen_ + 1] = digits_[mult3_ * (mult3_ - 1 - ilat) + ilon + 1];
61 gars.resize(baselen_ + prec);
62 copy(gars1, gars1 + baselen_ + prec, gars.begin());
66 int& prec,
bool centerp) {
67 int len = int(gars.length());
69 toupper(gars[0]) ==
'I' &&
70 toupper(gars[1]) ==
'N' &&
71 toupper(gars[2]) ==
'V') {
76 throw GeographicErr(
"GARS must have at least 5 characters " + gars);
78 throw GeographicErr(
"GARS can have at most 7 characters " + gars);
79 int prec1 = len - baselen_;
81 for (
int c = 0; c < lonlen_; ++c) {
85 ilon = ilon * baselon_ + k;
87 if (!(ilon >= 1 && ilon <= 2 *
Math::td))
88 throw GeographicErr(
"Initial digits in GARS must lie in [1, 720] " +
92 for (
int c = 0; c < latlen_; ++c) {
95 throw GeographicErr(
"Illegal letters in GARS " + gars.substr(3,2));
96 ilat = ilat * baselat_ + k;
99 throw GeographicErr(
"GARS letters must lie in [AA, QZ] " + gars);
102 lat1 = ilat + latorig_ * unit,
103 lon1 = ilon + lonorig_ * unit;
106 if (!(k >= 1 && k <= mult2_ * mult2_))
107 throw GeographicErr(
"6th character in GARS must [1, 4] " + gars);
110 lat1 = mult2_ * lat1 + (mult2_ - 1 - k / mult2_);
111 lon1 = mult2_ * lon1 + (k % mult2_);
115 throw GeographicErr(
"7th character in GARS must [1, 9] " + gars);
118 lat1 = mult3_ * lat1 + (mult3_ - 1 - k / mult3_);
119 lon1 = mult3_ * lon1 + (k % mult3_);
123 unit *= 2; lat1 = 2 * lat1 + 1; lon1 = 2 * lon1 + 1;
Header for GeographicLib::GARS class.
Header for GeographicLib::Utility class.
static void Reverse(const std::string &gars, real &lat, real &lon, int &prec, bool centerp=true)
static void Forward(real lat, real lon, int prec, std::string &gars)
Exception handling for GeographicLib.
static T AngNormalize(T x)
@ hd
degrees per half turn
@ qd
degrees per quarter turn
static int lookup(const std::string &s, char c)
static std::string str(T x, int p=-1)
Namespace for GeographicLib.