00001 #pragma once 00002 /** 00003 * \file NETGeographicLib/Geohash.h 00004 * \brief Header for NETGeographicLib::Geohash class 00005 * 00006 * NETGeographicLib is copyright (c) Scott Heiman (2013) 00007 * GeographicLib is Copyright (c) Charles Karney (2010-2012) 00008 * <charles@karney.com> and licensed under the MIT/X11 License. 00009 * For more information, see 00010 * http://geographiclib.sourceforge.net/ 00011 **********************************************************************/ 00012 00013 namespace NETGeographicLib 00014 { 00015 /** 00016 * \brief .NET wrapper for GeographicLib::Geohash. 00017 * 00018 * Geohashes are described in 00019 * - http://en.wikipedia.org/wiki/Geohash 00020 * - http://geohash.org/ 00021 * . 00022 * They provide a compact string representation of a particular geographic 00023 * location (expressed as latitude and longitude), with the property that if 00024 * trailing characters are dropped from the string the geographic location 00025 * remains nearby. 00026 * 00027 * C# Example: 00028 * \include example-Geohash.cs 00029 * Managed C++ Example: 00030 * \include example-Geohash.cpp 00031 * Visual Basic Example: 00032 * \include example-Geohash.vb 00033 **********************************************************************/ 00034 public ref class Geohash 00035 { 00036 private: 00037 // hide the constructor since all members of this class are static. 00038 Geohash() {} 00039 public: 00040 00041 /** 00042 * Convert from geographic coordinates to a geohash. 00043 * 00044 * @param[in] lat latitude of point (degrees). 00045 * @param[in] lon longitude of point (degrees). 00046 * @param[in] len the length of the resulting geohash. 00047 * @param[out] geohash the geohash. 00048 * @exception GeographicErr if \e la is not in [−90°, 00049 * 90°]. 00050 * @exception GeographicErr if \e lon is not in [−540°, 00051 * 540°). 00052 * @exception std::bad_alloc if memory for \e geohash can't be allocated. 00053 * 00054 * Internally, \e len is first put in the range [0, 18]. 00055 * 00056 * If \e lat or \e lon is NaN, the returned geohash is "nan". 00057 **********************************************************************/ 00058 static void Forward(double lat, double lon, int len, 00059 [System::Runtime::InteropServices::Out] System::String^% geohash); 00060 00061 /** 00062 * Convert from a geohash to geographic coordinates. 00063 * 00064 * @param[in] geohash the geohash. 00065 * @param[out] lat latitude of point (degrees). 00066 * @param[out] lon longitude of point (degrees). 00067 * @param[out] len the length of the geohash. 00068 * @param[in] centerp if true (the default) return the center of the 00069 * geohash location, otherwise return the south-west corner. 00070 * @exception GeographicErr if \e geohash contains illegal characters. 00071 * 00072 * Only the first 18 characters for \e geohash are considered. The case of 00073 * the letters in \e geohash is ignored. 00074 * 00075 * If the first three characters in \e geohash are "nan", then \e lat and 00076 * \e lon are set to NaN. 00077 **********************************************************************/ 00078 static void Reverse(System::String^ geohash, 00079 [System::Runtime::InteropServices::Out] double% lat, 00080 [System::Runtime::InteropServices::Out] double% lon, 00081 [System::Runtime::InteropServices::Out] int% len, 00082 bool centerp); 00083 00084 /** 00085 * The latitude resolution of a geohash. 00086 * 00087 * @param[in] len the length of the geohash. 00088 * @return the latitude resolution (degrees). 00089 * 00090 * Internally, \e len is first put in the range [0, 18]. 00091 **********************************************************************/ 00092 static double LatitudeResolution(int len); 00093 00094 /** 00095 * The longitude resolution of a geohash. 00096 * 00097 * @param[in] len the length of the geohash. 00098 * @return the longitude resolution (degrees). 00099 * 00100 * Internally, \e len is first put in the range [0, 18]. 00101 **********************************************************************/ 00102 static double LongitudeResolution(int len); 00103 00104 /** 00105 * The geohash length required to meet a given geographic resolution. 00106 * 00107 * @param[in] res the minimum of resolution in latitude and longitude 00108 * (degrees). 00109 * @return geohash length. 00110 * 00111 * The returned length is in the range [0, 18]. 00112 **********************************************************************/ 00113 static int GeohashLength(double res); 00114 00115 /** 00116 * The geohash length required to meet a given geographic resolution. 00117 * 00118 * @param[in] latres the resolution in latitude (degrees). 00119 * @param[in] lonres the resolution in longitude (degrees). 00120 * @return geohash length. 00121 * 00122 * The returned length is in the range [0, 18]. 00123 **********************************************************************/ 00124 static int GeohashLength(double latres, double lonres); 00125 00126 /** 00127 * The decimal geographic precision required to match a given geohash 00128 * length. This is the number of digits needed after decimal point in a 00129 * decimal degrees representation. 00130 * 00131 * @param[in] len the length of the geohash. 00132 * @return the decimal precision (may be negative). 00133 * 00134 * Internally, \e len is first put in the range [0, 18]. The returned 00135 * decimal precision is in the range [−2, 12]. 00136 **********************************************************************/ 00137 static int DecimalPrecision(int len); 00138 }; 00139 } // namespace NETGeographicLib