17 const char*
const GARS::digits_ =
"0123456789";
18 const char*
const GARS::letters_ =
"ABCDEFGHJKLMNPQRSTUVWXYZ";
23 +
"d not in [-90d, 90d]");
29 if (lon == 180) lon = -180;
30 if (lat == 90) lat *= (1 - numeric_limits<real>::epsilon() / 2);
31 prec = max(0, min(
int(maxprec_), prec));
33 x = int(floor(lon * m_)) - lonorig_ * m_,
34 y = int(floor(lat * m_)) - latorig_ * m_,
35 ilon = x * mult1_ / m_,
36 ilat = y * mult1_ / m_;
37 x -= ilon * m_ / mult1_; y -= ilat * m_ / mult1_;
40 for (
int c = lonlen_; c--;) {
41 gars1[c] = digits_[ ilon % baselon_]; ilon /= baselon_;
43 for (
int c = latlen_; c--;) {
44 gars1[lonlen_ + c] = letters_[ilat % baselat_]; ilat /= baselat_;
47 ilon = x / mult3_; ilat = y / mult3_;
48 gars1[baselen_] = digits_[mult2_ * (mult2_ - 1 - ilat) + ilon + 1];
50 ilon = x % mult3_; ilat = y % mult3_;
51 gars1[baselen_ + 1] = digits_[mult3_ * (mult3_ - 1 - ilat) + ilon + 1];
54 gars.resize(baselen_ + prec);
55 copy(gars1, gars1 + baselen_ + prec, gars.begin());
59 int& prec,
bool centerp) {
60 int len = int(gars.length());
62 toupper(gars[0]) ==
'I' &&
63 toupper(gars[1]) ==
'N' &&
64 toupper(gars[2]) ==
'V') {
69 throw GeographicErr(
"GARS must have at least 5 characters " + gars);
71 throw GeographicErr(
"GARS can have at most 7 characters " + gars);
72 int prec1 = len - baselen_;
74 for (
int c = 0; c < lonlen_; ++c) {
78 ilon = ilon * baselon_ + k;
80 if (!(ilon >= 1 && ilon <= 720))
81 throw GeographicErr(
"Initial digits in GARS must lie in [1, 720] " +
85 for (
int c = 0; c < latlen_; ++c) {
88 throw GeographicErr(
"Illegal letters in GARS " + gars.substr(3,2));
89 ilat = ilat * baselat_ + k;
92 throw GeographicErr(
"GARS letters must lie in [AA, QZ] " + gars);
95 lat1 = ilat + latorig_ * unit,
96 lon1 = ilon + lonorig_ * unit;
99 if (!(k >= 1 && k <= mult2_ * mult2_))
100 throw GeographicErr(
"6th character in GARS must [1, 4] " + gars);
103 lat1 = mult2_ * lat1 + (mult2_ - 1 - k / mult2_);
104 lon1 = mult2_ * lon1 + (k % mult2_);
108 throw GeographicErr(
"7th character in GARS must [1, 9] " + gars);
111 lat1 = mult3_ * lat1 + (mult3_ - 1 - k / mult3_);
112 lon1 = mult3_ * lon1 + (k % mult3_);
116 unit *= 2; lat1 = 2 * lat1 + 1; lon1 = 2 * lon1 + 1;