Geohash.hpp
Go to the documentation of this file.
1 
10 #if !defined(GEOGRAPHICLIB_GEOHASH_HPP)
11 #define GEOGRAPHICLIB_GEOHASH_HPP 1
12 
14 
15 #if defined(_MSC_VER)
16 // Squelch warnings about dll vs string
17 # pragma warning (push)
18 # pragma warning (disable: 4251)
19 #endif
20 
21 namespace GeographicLib {
22 
41  private:
42  typedef Math::real real;
43  static const int maxlen_ = 18;
44  static const unsigned long long mask_ = 1ULL << 45;
45  static const char* const lcdigits_;
46  static const char* const ucdigits_;
47  Geohash(); // Disable constructor
48 
49  public:
50 
67  static void Forward(real lat, real lon, int len, std::string& geohash);
68 
88  static void Reverse(const std::string& geohash, real& lat, real& lon,
89  int& len, bool centerp = true);
90 
100  using std::ldexp;
101  len = (std::max)(0, (std::min)(int(maxlen_), len));
102  return ldexp(real(180), -(5 * len / 2));
103  }
104 
114  using std::ldexp;
115  len = (std::max)(0, (std::min)(int(maxlen_), len));
116  return ldexp(real(360), -(5 * len - 5 * len / 2));
117  }
118 
128  static int GeohashLength(real res) {
129  using std::abs; res = abs(res);
130  for (int len = 0; len < maxlen_; ++len)
131  if (LongitudeResolution(len) <= res)
132  return len;
133  return maxlen_;
134  }
135 
145  static int GeohashLength(real latres, real lonres) {
146  using std::abs;
147  latres = abs(latres);
148  lonres = abs(lonres);
149  for (int len = 0; len < maxlen_; ++len)
150  if (LatitudeResolution(len) <= latres &&
151  LongitudeResolution(len) <= lonres)
152  return len;
153  return maxlen_;
154  }
155 
167  static int DecimalPrecision(int len) {
168  using std::floor; using std::log;
169  return -int(floor(log(LatitudeResolution(len))/log(Math::real(10))));
170  }
171 
172  };
173 
174 } // namespace GeographicLib
175 
176 #if defined(_MSC_VER)
177 # pragma warning (pop)
178 #endif
179 
180 #endif // GEOGRAPHICLIB_GEOHASH_HPP
static Math::real LongitudeResolution(int len)
Definition: Geohash.hpp:113
#define max(a, b)
Definition: datatypes.h:20
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:91
float real
Definition: datatypes.h:10
static const double lat
#define min(a, b)
Definition: datatypes.h:19
EIGEN_DEVICE_FUNC const LogReturnType log() const
static int GeohashLength(real res)
Definition: Geohash.hpp:128
static const char *const ucdigits_
Definition: Geohash.hpp:46
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
EIGEN_DEVICE_FUNC const FloorReturnType floor() const
Conversions for geohashes.
Definition: Geohash.hpp:40
Namespace for GeographicLib.
static int GeohashLength(real latres, real lonres)
Definition: Geohash.hpp:145
static int DecimalPrecision(int len)
Definition: Geohash.hpp:167
Header for GeographicLib::Constants class.
static const char *const lcdigits_
Definition: Geohash.hpp:45
static const double lon
size_t len(handle h)
Get the length of a Python object.
Definition: pytypes.h:2244
#define abs(x)
Definition: datatypes.h:17
static Math::real LatitudeResolution(int len)
Definition: Geohash.hpp:99


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:18