17 const char*
const Geohash::lcdigits_ =
"0123456789bcdefghjkmnpqrstuvwxyz";
18 const char*
const Geohash::ucdigits_ =
"0123456789BCDEFGHJKMNPQRSTUVWXYZ";
22 static const real shift = ldexp(real(1), 45);
23 static const real loneps =
Math::hd / shift;
24 static const real lateps =
Math::qd / shift;
27 +
"d not in [-" + to_string(
Math::qd)
28 +
"d, " + to_string(
Math::qd) +
"d]");
29 if (isnan(lat) || isnan(lon)) {
33 if (lat ==
Math::qd) lat -= lateps / 2;
38 len = max(0, min(
int(maxlen_), len));
40 ulon = (
unsigned long long)(floor(lon/loneps) + shift),
41 ulat = (
unsigned long long)(floor(lat/lateps) + shift);
42 char geohash1[maxlen_];
44 for (
unsigned i = 0; i < 5 * unsigned(len);) {
46 byte = (
byte << 1) +
unsigned((ulon & mask_) != 0);
49 byte = (
byte << 1) +
unsigned((ulat & mask_) != 0);
54 geohash1[(i/5)-1] = lcdigits_[
byte];
59 copy(geohash1, geohash1 + len, geohash.begin());
63 int& len,
bool centerp) {
64 static const real shift = ldexp(real(1), 45);
65 static const real loneps =
Math::hd / shift;
66 static const real lateps =
Math::qd / shift;
67 int len1 = min(
int(maxlen_),
int(geohash.length()));
69 ((toupper(geohash[0]) ==
'I' &&
70 toupper(geohash[1]) ==
'N' &&
71 toupper(geohash[2]) ==
'V') ||
73 (toupper(geohash[1]) ==
'A' &&
74 toupper(geohash[0]) ==
'N' &&
75 toupper(geohash[2]) ==
'N'))) {
79 unsigned long long ulon = 0, ulat = 0;
80 for (
unsigned k = 0, j = 0; k < unsigned(len1); ++k) {
83 throw GeographicErr(
"Illegal character in geohash " + geohash);
84 for (
unsigned m = 16; m; m >>= 1) {
86 ulon = (ulon << 1) +
unsigned((
byte & m) != 0);
88 ulat = (ulat << 1) +
unsigned((
byte & m) != 0);
92 ulon <<= 1; ulat <<= 1;
97 int s = 5 * (maxlen_ - len1);
Header for GeographicLib::Geohash class.
Header for GeographicLib::Utility class.
Exception handling for GeographicLib.
static void Forward(real lat, real lon, int len, std::string &geohash)
static void Reverse(const std::string &geohash, real &lat, real &lon, int &len, bool centerp=true)
static constexpr int qd
degrees per quarter turn
static T AngNormalize(T x)
static constexpr int hd
degrees per half turn
static int lookup(const std::string &s, char c)
static std::string str(T x, int p=-1)
Namespace for GeographicLib.