17 const string Georef::digits_ =
"0123456789";
18 const string Georef::lontile_ =
"ABCDEFGHJKLMNPQRSTUVWXYZ";
19 const string Georef::lattile_ =
"ABCDEFGHJKLM";
20 const string Georef::degrees_ =
"ABCDEFGHJKLMNPQ";
25 +
"d not in [-90d, 90d]");
31 if (lat == 90) lat *= (1 - numeric_limits<real>::epsilon() / 2);
32 prec = max(-1, min(
int(maxprec_), prec));
33 if (prec == 1) ++prec;
36 GEOGRAPHICLIB_STATIC_ASSERT(numeric_limits<long long>::digits >= 45,
37 "long long not wide enough to store 21600e9");
38 const long long m = 60000000000LL;
40 x = (
long long)(floor(lon * m)) - lonorig_ * m,
41 y = (
long long)(floor(lat * m)) - latorig_ * m;
42 int ilon = int(x / m);
int ilat = int(y / m);
43 char georef1[maxlen_];
44 georef1[0] = lontile_[ilon / tile_];
45 georef1[1] = lattile_[ilat / tile_];
47 georef1[2] = degrees_[ilon % tile_];
48 georef1[3] = degrees_[ilat % tile_];
50 x -= m * ilon; y -= m * ilat;
51 long long d = (
long long)pow(
real(base_), maxprec_ - prec);
53 for (
int c = prec; c--;) {
54 georef1[baselen_ + c ] = digits_[x % base_]; x /= base_;
55 georef1[baselen_ + c + prec] = digits_[y % base_]; y /= base_;
59 georef.resize(baselen_ + 2 * prec);
60 copy(georef1, georef1 + baselen_ + 2 * prec, georef.begin());
64 int& prec,
bool centerp) {
65 int len = int(georef.length());
67 toupper(georef[0]) ==
'I' &&
68 toupper(georef[1]) ==
'N' &&
69 toupper(georef[2]) ==
'V') {
73 if (len < baselen_ - 2)
74 throw GeographicErr(
"Georef must start with at least 2 letters "
76 int prec1 = (2 + len - baselen_) / 2 - 1;
80 throw GeographicErr(
"Bad longitude tile letter in georef " + georef);
81 real lon1 = k + lonorig_ / tile_;
84 throw GeographicErr(
"Bad latitude tile letter in georef " + georef);
85 real lat1 = k + latorig_ / tile_;
91 throw GeographicErr(
"Bad longitude degree letter in georef " + georef);
92 lon1 = lon1 * tile_ + k;
94 throw GeographicErr(
"Missing latitude degree letter in georef "
98 throw GeographicErr(
"Bad latitude degree letter in georef " + georef);
99 lat1 = lat1 * tile_ + k;
101 if (georef.find_first_not_of(digits_, baselen_) != string::npos)
102 throw GeographicErr(
"Non digits in trailing portion of georef "
103 + georef.substr(baselen_));
105 throw GeographicErr(
"Georef must end with an even number of digits "
106 + georef.substr(baselen_));
108 throw GeographicErr(
"Georef needs at least 4 digits for minutes "
109 + georef.substr(baselen_));
110 if (prec1 > maxprec_)
112 +
" digits in georef " + georef.substr(baselen_));
113 for (
int i = 0; i < prec1; ++i) {
114 int m = i ? base_ : 6;
119 if (!(i || (x < m && y < m)))
120 throw GeographicErr(
"Minutes terms in georef must be less than 60 "
121 + georef.substr(baselen_));
128 unit *= 2; lat1 = 2 * lat1 + 1; lon1 = 2 * lon1 + 1;
130 lat = (tile_ * lat1) / unit;
131 lon = (tile_ * lon1) / unit;
static T AngNormalize(T x)
Header for GeographicLib::Georef class.
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
static void Forward(real lat, real lon, int prec, std::string &georef)
Namespace for GeographicLib.
static std::string str(T x, int p=-1)
static void Reverse(const std::string &georef, real &lat, real &lon, int &prec, bool centerp=true)
Exception handling for GeographicLib.
static int lookup(const std::string &s, char c)