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 string Geohash::lcdigits_ =
"0123456789bcdefghjkmnpqrstuvwxyz";
20 const string Geohash::ucdigits_ =
"0123456789BCDEFGHJKMNPQRSTUVWXYZ";
25 +
"d not in [-90d, 90d]");
26 if (lon < -540 || lon >= 540)
28 +
"d not in [-540d, 540d)");
33 if (lat == 90) lat -= lateps() / 2;
37 len = max(0, min(
int(maxlen_), len));
39 ulon = (
unsigned long long)(floor(lon/loneps()) + shift()),
40 ulat = (
unsigned long long)(floor(lat/lateps()) + shift());
41 char geohash1[maxlen_];
43 for (
unsigned i = 0; i < 5 * unsigned(len);) {
45 byte = (byte << 1) +
unsigned((ulon & mask_) != 0);
48 byte = (byte << 1) +
unsigned((ulat & mask_) != 0);
53 geohash1[(i/5)-1] = lcdigits_[byte];
58 copy(geohash1, geohash1 + len, geohash.begin());
62 int& len,
bool centerp) {
63 len = min(
int(maxlen_),
int(geohash.length()));
65 toupper(geohash[0]) ==
'N' &&
66 toupper(geohash[1]) ==
'A' &&
67 toupper(geohash[2]) ==
'N') {
71 unsigned long long ulon = 0, ulat = 0;
72 for (
unsigned k = 0, j = 0; k < unsigned(len); ++k) {
75 throw GeographicErr(
"Illegal character in geohash " + geohash);
76 for (
unsigned m = 16; m; m >>= 1) {
78 ulon = (ulon << 1) +
unsigned((byte & m) != 0);
80 ulat = (ulat << 1) +
unsigned((byte & m) != 0);
84 ulon <<= 1; ulat <<= 1;
89 int s = 5 * (maxlen_ - len);
92 lon = ulon * loneps() - 180;
93 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.