15# pragma warning (disable: 5055)
22 const char*
const Geohash::lcdigits_ =
"0123456789bcdefghjkmnpqrstuvwxyz";
23 const char*
const Geohash::ucdigits_ =
"0123456789BCDEFGHJKMNPQRSTUVWXYZ";
27 static const real shift = ldexp(real(1), 45);
28 static const real loneps =
Math::hd / shift;
29 static const real lateps =
Math::qd / shift;
32 +
"d not in [-" + to_string(
Math::qd)
33 +
"d, " + to_string(
Math::qd) +
"d]");
34 if (isnan(lat) || isnan(lon)) {
38 if (lat ==
Math::qd) lat -= lateps / 2;
43 len = max(0, min(
int(maxlen_), len));
45 ulon = (
unsigned long long)(floor(lon/loneps) + shift),
46 ulat = (
unsigned long long)(floor(lat/lateps) + shift);
47 char geohash1[maxlen_];
49 for (
unsigned i = 0; i < 5 * unsigned(len);) {
51 byte = (
byte << 1) +
unsigned((ulon & mask_) != 0);
54 byte = (
byte << 1) +
unsigned((ulat & mask_) != 0);
59 geohash1[(i/5)-1] = lcdigits_[
byte];
64 copy(geohash1, geohash1 + len, geohash.begin());
68 int& len,
bool centerp) {
69 static const real shift = ldexp(real(1), 45);
70 static const real loneps =
Math::hd / shift;
71 static const real lateps =
Math::qd / shift;
72 int len1 = min(
int(maxlen_),
int(geohash.length()));
74 ((toupper(geohash[0]) ==
'I' &&
75 toupper(geohash[1]) ==
'N' &&
76 toupper(geohash[2]) ==
'V') ||
78 (toupper(geohash[1]) ==
'A' &&
79 toupper(geohash[0]) ==
'N' &&
80 toupper(geohash[2]) ==
'N'))) {
84 unsigned long long ulon = 0, ulat = 0;
85 for (
unsigned k = 0, j = 0; k < unsigned(len1); ++k) {
88 throw GeographicErr(
"Illegal character in geohash " + geohash);
89 for (
unsigned m = 16; m; m >>= 1) {
91 ulon = (ulon << 1) +
unsigned((
byte & m) != 0);
93 ulat = (ulat << 1) +
unsigned((
byte & m) != 0);
97 ulon <<= 1; ulat <<= 1;
102 int s = 5 * (maxlen_ - len1);
104 ulat <<= s - (s / 2);
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 T AngNormalize(T x)
@ hd
degrees per half turn
@ qd
degrees per quarter turn
static int lookup(const std::string &s, char c)
static std::string str(T x, int p=-1)
Namespace for GeographicLib.