13 namespace GeographicLib {
17 const int Geohash::decprec_[] = {-2, -1, 0, 0, 1, 2, 3, 3, 4, 5,
18 6, 6, 7, 8, 9, 9, 10, 11, 12};
19 const Math::real Geohash::loneps_ = 180 * std::pow(0.5, 45);
20 const Math::real Geohash::lateps_ = 90 * std::pow(0.5, 45);
21 const Math::real Geohash::shift_ = std::pow(2.0, 45);
22 const string Geohash::lcdigits_ =
"0123456789bcdefghjkmnpqrstuvwxyz";
23 const string Geohash::ucdigits_ =
"0123456789BCDEFGHJKMNPQRSTUVWXYZ";
28 +
"d not in [-90d, 90d]");
29 if (lon < -540 || lon >= 540)
31 +
"d not in [-540d, 540d)");
36 if (lat == 90) lat -= lateps_ / 2;
40 len = max(0, min(
int(maxlen_), len));
42 ulon = (
unsigned long long)(floor(lon/loneps_) + shift_),
43 ulat = (
unsigned long long)(floor(lat/lateps_) + shift_);
44 char geohash1[maxlen_];
46 for (
unsigned i = 0; i < 5 * unsigned(len);) {
48 byte = (byte << 1) +
unsigned((ulon & mask_) != 0);
51 byte = (byte << 1) +
unsigned((ulat & mask_) != 0);
56 geohash1[(i/5)-1] = lcdigits_[byte];
61 copy(geohash1, geohash1 + len, geohash.begin());
65 int& len,
bool centerp) {
66 len = min(
int(maxlen_),
int(geohash.length()));
68 toupper(geohash[0]) ==
'N' &&
69 toupper(geohash[1]) ==
'A' &&
70 toupper(geohash[2]) ==
'N') {
71 lat = lon = Math::NaN<real>();
74 unsigned long long ulon = 0, ulat = 0;
75 for (
unsigned k = 0, j = 0; k < unsigned(len); ++k) {
78 throw GeographicErr(
"Illegal character in geohash " + geohash);
79 for (
unsigned i = 0, m = 16; i < 5; ++i, m >>= 1) {
81 ulon = (ulon << 1) +
unsigned((byte & m) != 0);
83 ulat = (ulat << 1) +
unsigned((byte & m) != 0);
87 ulon <<= 1; ulat <<= 1;
92 int s = 5 * (maxlen_ - len);
95 lon = ulon * loneps_ - 180;
96 lat = ulat * lateps_ - 90;
static T AngNormalize(T x)
Header for GeographicLib::Utility class.
static std::string str(T x, int p=-1)
static void Forward(real lat, real lon, int len, std::string &geohash)
Exception handling for GeographicLib.
static int lookup(const std::string &s, char c)
static void Reverse(const std::string &geohash, real &lat, real &lon, int &len, bool centerp=true)
Header for GeographicLib::Geohash class.