17 const char*
const GARS::digits_ =
"0123456789";
18 const char*
const GARS::letters_ =
"ABCDEFGHJKLMNPQRSTUVWXYZ";
24 +
"d not in [-90d, 90d]");
25 if (isnan(lat) || isnan(lon)) {
30 if (lon == 180) lon = -180;
31 if (lat == 90) lat *= (1 - numeric_limits<real>::epsilon() / 2);
32 prec = max(0, min(
int(maxprec_), prec));
34 x = int(floor(lon * m_)) - lonorig_ * m_,
35 y = int(floor(lat * m_)) - latorig_ * m_,
36 ilon = x * mult1_ / m_,
37 ilat = y * mult1_ / m_;
38 x -= ilon * m_ / mult1_; y -= ilat * m_ / mult1_;
41 for (
int c = lonlen_; c--;) {
42 gars1[c] = digits_[ ilon % baselon_]; ilon /= baselon_;
44 for (
int c = latlen_; c--;) {
45 gars1[lonlen_ + c] = letters_[ilat % baselat_]; ilat /= baselat_;
48 ilon = x / mult3_; ilat = y / mult3_;
49 gars1[baselen_] = digits_[mult2_ * (mult2_ - 1 - ilat) + ilon + 1];
51 ilon = x % mult3_; ilat = y % mult3_;
52 gars1[baselen_ + 1] = digits_[mult3_ * (mult3_ - 1 - ilat) + ilon + 1];
55 gars.resize(baselen_ + prec);
56 copy(gars1, gars1 + baselen_ + prec, gars.begin());
60 int& prec,
bool centerp) {
61 int len = int(gars.length());
63 toupper(gars[0]) ==
'I' &&
64 toupper(gars[1]) ==
'N' &&
65 toupper(gars[2]) ==
'V') {
70 throw GeographicErr(
"GARS must have at least 5 characters " + gars);
72 throw GeographicErr(
"GARS can have at most 7 characters " + gars);
73 int prec1 = len - baselen_;
75 for (
int c = 0; c < lonlen_; ++c) {
79 ilon = ilon * baselon_ + k;
81 if (!(ilon >= 1 && ilon <= 720))
82 throw GeographicErr(
"Initial digits in GARS must lie in [1, 720] " +
86 for (
int c = 0; c < latlen_; ++c) {
89 throw GeographicErr(
"Illegal letters in GARS " + gars.substr(3,2));
90 ilat = ilat * baselat_ + k;
93 throw GeographicErr(
"GARS letters must lie in [AA, QZ] " + gars);
96 lat1 = ilat + latorig_ * unit,
97 lon1 = ilon + lonorig_ * unit;
100 if (!(k >= 1 && k <= mult2_ * mult2_))
101 throw GeographicErr(
"6th character in GARS must [1, 4] " + gars);
104 lat1 = mult2_ * lat1 + (mult2_ - 1 - k / mult2_);
105 lon1 = mult2_ * lon1 + (k % mult2_);
109 throw GeographicErr(
"7th character in GARS must [1, 9] " + gars);
112 lat1 = mult3_ * lat1 + (mult3_ - 1 - k / mult3_);
113 lon1 = mult3_ * lon1 + (k % mult3_);
117 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)
static int lookup(const std::string &s, char c)
static std::string str(T x, int p=-1)
Namespace for GeographicLib.