GNSS-SDR 0.0.21
An Open Source GNSS Software Defined Receiver
Loading...
Searching...
No Matches
geohash.h
Go to the documentation of this file.
1/*!
2 * \file geohash.h
3 * \brief Interface of a class that encodes / decodes geohashes
4 * \author Carles Fernandez-Prades, 2023. cfernandez(at)cttc.es
5 *
6 *
7 * -----------------------------------------------------------------------------
8 *
9 * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
10 * This file is part of GNSS-SDR.
11 *
12 * Copyright (C) 2010-2023 (see AUTHORS file for a list of contributors)
13 * SPDX-License-Identifier: GPL-3.0-or-later
14 *
15 * -----------------------------------------------------------------------------
16 */
17
18
19#ifndef GNSS_SDR_GEOHASH_H
20#define GNSS_SDR_GEOHASH_H
21
22#include <array>
23#include <string>
24
25/** \addtogroup PVT
26 * \{ */
27/** \addtogroup PVT_libs
28 * \{ */
29
30/*!
31 * \brief Class for geohash encoding / decoding
32 * See https://en.wikipedia.org/wiki/Geohash
33 */
34class Geohash
35{
36public:
37 Geohash() = default;
38
39 /**
40 * Encodes latitude/longitude to geohash, either to specified precision or
41 * to automatically evaluated precision.
42 *
43 * @param {double} lat - Latitude in degrees.
44 * @param {double} lon - Longitude in degrees.
45 * @param {int} [precision] - Number of characters in resulting geohash.
46 * @returns {string} Geohash of supplied latitude/longitude.
47 * @throws Invalid geohash.
48 *
49 */
50 std::string encode(double lat, double lon, int precision = -1) const;
51
52 /**
53 * Decode geohash to latitude/longitude (location is approximate centre of
54 * geohash cell, to reasonable precision).
55 *
56 * @param {string} geohash - Geohash string to be converted to
57 * latitude/longitude.
58 * @returns {lat, lon} (Center of) geohashed location.
59 * @throws Invalid geohash.
60 *
61 */
62 std::array<double, 2> decode(std::string geohash) const;
63
64private:
65 /*
66 * Returns SW/NE latitude/longitude bounds of specified geohash.
67 */
68 std::array<double, 4> bounds(std::string geohash) const;
69 std::string base32{"0123456789bcdefghjkmnpqrstuvwxyz"};
70};
71
72/** \} */
73/** \} */
74#endif // GNSS_SDR_GEOHASH_H
std::array< double, 2 > decode(std::string geohash) const
std::string encode(double lat, double lon, int precision=-1) const