NETGeographicLib  1.51
Geohash.h
Go to the documentation of this file.
1 #pragma once
2 /**
3  * \file NETGeographicLib/Geohash.h
4  * \brief Header for NETGeographicLib::Geohash class
5  *
6  * NETGeographicLib is copyright (c) Scott Heiman (2013)
7  * GeographicLib is Copyright (c) Charles Karney (2010-2012)
8  * <charles@karney.com> and licensed under the MIT/X11 License.
9  * For more information, see
10  * https://geographiclib.sourceforge.io/
11  **********************************************************************/
12 
13 namespace NETGeographicLib
14 {
15  /**
16  * \brief .NET wrapper for GeographicLib::Geohash.
17  *
18  * Geohashes are described in
19  * - https://en.wikipedia.org/wiki/Geohash
20  * - http://geohash.org/ (this link is broken as of 2012-12-11)
21  * .
22  * They provide a compact string representation of a particular geographic
23  * location (expressed as latitude and longitude), with the property that if
24  * trailing characters are dropped from the string the geographic location
25  * remains nearby.
26  *
27  * C# Example:
28  * \include example-Geohash.cs
29  * Managed C++ Example:
30  * \include example-Geohash.cpp
31  * Visual Basic Example:
32  * \include example-Geohash.vb
33  **********************************************************************/
34  public ref class Geohash
35  {
36  private:
37  // hide the constructor since all members of this class are static.
38  Geohash() {}
39  public:
40 
41  /**
42  * Convert from geographic coordinates to a geohash.
43  *
44  * @param[in] lat latitude of point (degrees).
45  * @param[in] lon longitude of point (degrees).
46  * @param[in] len the length of the resulting geohash.
47  * @param[out] geohash the geohash.
48  * @exception GeographicErr if \e lat is not in [&minus;90&deg;,
49  * 90&deg;].
50  * @exception std::bad_alloc if memory for \e geohash can't be allocated.
51  *
52  * Internally, \e len is first put in the range [0, 18].
53  *
54  * If \e lat or \e lon is NaN, the returned geohash is "nan".
55  **********************************************************************/
56  static void Forward(double lat, double lon, int len,
57  [System::Runtime::InteropServices::Out] System::String^% geohash);
58 
59  /**
60  * Convert from a geohash to geographic coordinates.
61  *
62  * @param[in] geohash the geohash.
63  * @param[out] lat latitude of point (degrees).
64  * @param[out] lon longitude of point (degrees).
65  * @param[out] len the length of the geohash.
66  * @param[in] centerp if true (the default) return the center of the
67  * geohash location, otherwise return the south-west corner.
68  * @exception GeographicErr if \e geohash contains illegal characters.
69  *
70  * Only the first 18 characters for \e geohash are considered. The case of
71  * the letters in \e geohash is ignored.
72  *
73  * If the first three characters in \e geohash are "nan", then \e lat and
74  * \e lon are set to NaN.
75  **********************************************************************/
76  static void Reverse(System::String^ geohash,
77  [System::Runtime::InteropServices::Out] double% lat,
78  [System::Runtime::InteropServices::Out] double% lon,
79  [System::Runtime::InteropServices::Out] int% len,
80  bool centerp);
81 
82  /**
83  * The latitude resolution of a geohash.
84  *
85  * @param[in] len the length of the geohash.
86  * @return the latitude resolution (degrees).
87  *
88  * Internally, \e len is first put in the range [0, 18].
89  **********************************************************************/
90  static double LatitudeResolution(int len);
91 
92  /**
93  * The longitude resolution of a geohash.
94  *
95  * @param[in] len the length of the geohash.
96  * @return the longitude resolution (degrees).
97  *
98  * Internally, \e len is first put in the range [0, 18].
99  **********************************************************************/
100  static double LongitudeResolution(int len);
101 
102  /**
103  * The geohash length required to meet a given geographic resolution.
104  *
105  * @param[in] res the minimum of resolution in latitude and longitude
106  * (degrees).
107  * @return geohash length.
108  *
109  * The returned length is in the range [0, 18].
110  **********************************************************************/
111  static int GeohashLength(double res);
112 
113  /**
114  * The geohash length required to meet a given geographic resolution.
115  *
116  * @param[in] latres the resolution in latitude (degrees).
117  * @param[in] lonres the resolution in longitude (degrees).
118  * @return geohash length.
119  *
120  * The returned length is in the range [0, 18].
121  **********************************************************************/
122  static int GeohashLength(double latres, double lonres);
123 
124  /**
125  * The decimal geographic precision required to match a given geohash
126  * length. This is the number of digits needed after decimal point in a
127  * decimal degrees representation.
128  *
129  * @param[in] len the length of the geohash.
130  * @return the decimal precision (may be negative).
131  *
132  * Internally, \e len is first put in the range [0, 18]. The returned
133  * decimal precision is in the range [&minus;2, 12].
134  **********************************************************************/
135  static int DecimalPrecision(int len);
136  };
137 } // namespace NETGeographicLib
static double LongitudeResolution(int len)
static int GeohashLength(double res)
static void Forward(double lat, double lon, int len, [System::Runtime::InteropServices::Out] System::String^% geohash)
.NET wrapper for GeographicLib::Geohash.
Definition: Geohash.h:34
static void Reverse(System::String^ geohash, [System::Runtime::InteropServices::Out] double% lat, [System::Runtime::InteropServices::Out] double% lon, [System::Runtime::InteropServices::Out] int% len, bool centerp)
static int DecimalPrecision(int len)
static double LatitudeResolution(int len)