Static Public Member Functions | Private Member Functions | List of all members
NETGeographicLib::Geohash Class Reference

.NET wrapper for GeographicLib::Geohash. More...

#include <Geohash.h>

Static Public Member Functions

static int DecimalPrecision (int len)
 
static void Forward (double lat, double lon, int len, [System::Runtime::InteropServices::Out] System::String^% geohash)
 
static int GeohashLength (double latres, double lonres)
 
static int GeohashLength (double res)
 
static double LatitudeResolution (int len)
 
static double LongitudeResolution (int len)
 
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)
 

Private Member Functions

 Geohash ()
 

Detailed Description

.NET wrapper for GeographicLib::Geohash.

Geohashes are described in

They provide a compact string representation of a particular geographic location (expressed as latitude and longitude), with the property that if trailing characters are dropped from the string the geographic location remains nearby.

C# Example:

using System;
namespace example_Geohash
{
class Program
{
static void Main(string[] args)
{
try {
{
// Sample forward calculation
double lat = 57.64911, lon = 10.40744; // Jutland (the wikipedia example)
string geohash;
int maxlen = Geohash.GeohashLength(1.0e-5);
for (int len = 0; len <= maxlen; ++len) {
Geohash.Forward(lat, lon, len, out geohash);
Console.WriteLine( geohash );
}
}
{
// Sample reverse calculation
string geohash = "u4pruydqqvj";
double lat, lon;
for (int i = 0; i <= geohash.Length; ++i) {
int len;
Geohash.Reverse(geohash.Substring(0, i), out lat, out lon, out len, true);
Console.WriteLine(String.Format("Length: {0} Latitude: {1} Longitude: {2}", len, lat, lon ) );
}
}
}
catch (GeographicErr e) {
Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
}
}
}
}

Managed C++ Example:

// Example of using the GeographicLib::Geohash class
#include <iostream>
#include <iomanip>
#include <exception>
#include <string>
using namespace std;
using namespace GeographicLib;
int main() {
try {
{
// Sample forward calculation
double lat = 57.64911, lon = 10.40744; // Jutland (the wikipedia example)
string geohash;
int maxlen = Geohash::GeohashLength(1.0e-5);
for (int len = 0; len <= maxlen; ++len) {
Geohash::Forward(lat, lon, len, geohash);
cout << len << " " << geohash << "\n";
}
}
{
// Sample reverse calculation
string geohash = "u4pruydqqvj";
double lat, lon;
cout << fixed;
for (unsigned i = 0; i <= geohash.length(); ++i) {
int len;
Geohash::Reverse(geohash.substr(0, i), lat, lon, len);
cout << setprecision(max(0, Geohash::DecimalPrecision(len)))
<< len << " " << lat << " " << lon << "\n";
}
}
}
catch (const exception& e) {
cerr << "Caught exception: " << e.what() << "\n";
return 1;
}
}

Visual Basic Example:

Imports NETGeographicLib
Module example_Geohash
Sub Main()
Try
' Sample forward calculation
Dim lat As Double = 57.64911, lon = 10.40744 ' Jutland (the wikipedia example)
Dim ghash As String
Dim maxlen As Integer = Geohash.GeohashLength(0.00001)
For len As Integer = 0 To maxlen
Geohash.Forward(lat, lon, len, ghash)
Console.WriteLine(ghash)
Next
' Sample reverse calculation
ghash = "u4pruydqqvj"
For i As Integer = 0 To ghash.Length - 1
Dim len As Integer
Geohash.Reverse(ghash.Substring(0, i), lat, lon, len, True)
Console.WriteLine(String.Format("Length: {0} Latitude: {1} Longitude: {2}", len, lat, lon))
Next
Catch ex As GeographicErr
Console.WriteLine(String.Format("Caught exception: {0}", ex.Message))
End Try
End Sub
End Module

Definition at line 34 of file Geohash.h.

Constructor & Destructor Documentation

◆ Geohash()

NETGeographicLib::Geohash::Geohash ( )
inlineprivate

Definition at line 38 of file Geohash.h.

Member Function Documentation

◆ DecimalPrecision()

int Geohash::DecimalPrecision ( int  len)
static

The decimal geographic precision required to match a given geohash length. This is the number of digits needed after decimal point in a decimal degrees representation.

Parameters
[in]lenthe length of the geohash.
Returns
the decimal precision (may be negative).

Internally, len is first put in the range [0, 18]. The returned decimal precision is in the range [−2, 12].

Definition at line 81 of file dotnet/NETGeographicLib/Geohash.cpp.

◆ Forward()

void Geohash::Forward ( double  lat,
double  lon,
int  len,
[System::Runtime::InteropServices::Out] System::String^%  geohash 
)
static

Convert from geographic coordinates to a geohash.

Parameters
[in]latlatitude of point (degrees).
[in]lonlongitude of point (degrees).
[in]lenthe length of the resulting geohash.
[out]geohashthe geohash.
Exceptions
GeographicErrif lat is not in [−90°, 90°].
std::bad_allocif memory for geohash can't be allocated.

Internally, len is first put in the range [0, 18].

If lat or lon is NaN, the returned geohash is "nan".

Definition at line 19 of file dotnet/NETGeographicLib/Geohash.cpp.

◆ GeohashLength() [1/2]

int Geohash::GeohashLength ( double  latres,
double  lonres 
)
static

The geohash length required to meet a given geographic resolution.

Parameters
[in]latresthe resolution in latitude (degrees).
[in]lonresthe resolution in longitude (degrees).
Returns
geohash length.

The returned length is in the range [0, 18].

Definition at line 75 of file dotnet/NETGeographicLib/Geohash.cpp.

◆ GeohashLength() [2/2]

int Geohash::GeohashLength ( double  res)
static

The geohash length required to meet a given geographic resolution.

Parameters
[in]resthe minimum of resolution in latitude and longitude (degrees).
Returns
geohash length.

The returned length is in the range [0, 18].

Definition at line 69 of file dotnet/NETGeographicLib/Geohash.cpp.

◆ LatitudeResolution()

double Geohash::LatitudeResolution ( int  len)
static

The latitude resolution of a geohash.

Parameters
[in]lenthe length of the geohash.
Returns
the latitude resolution (degrees).

Internally, len is first put in the range [0, 18].

Definition at line 57 of file dotnet/NETGeographicLib/Geohash.cpp.

◆ LongitudeResolution()

double Geohash::LongitudeResolution ( int  len)
static

The longitude resolution of a geohash.

Parameters
[in]lenthe length of the geohash.
Returns
the longitude resolution (degrees).

Internally, len is first put in the range [0, 18].

Definition at line 63 of file dotnet/NETGeographicLib/Geohash.cpp.

◆ Reverse()

void Geohash::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

Convert from a geohash to geographic coordinates.

Parameters
[in]geohashthe geohash.
[out]latlatitude of point (degrees).
[out]lonlongitude of point (degrees).
[out]lenthe length of the geohash.
[in]centerpif true (the default) return the center of the geohash location, otherwise return the south-west corner.
Exceptions
GeographicErrif geohash contains illegal characters.

Only the first 18 characters for geohash are considered. The case of the letters in geohash is ignored.

If the first three characters in geohash are "nan", then lat and lon are set to NaN.

Definition at line 34 of file dotnet/NETGeographicLib/Geohash.cpp.


The documentation for this class was generated from the following files:
NETGeographicLib::Geohash::DecimalPrecision
static int DecimalPrecision(int len)
Definition: dotnet/NETGeographicLib/Geohash.cpp:81
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GeographicLib
Namespace for GeographicLib.
Definition: JacobiConformal.hpp:15
NETGeographicLib::Geohash::GeohashLength
static int GeohashLength(double res)
Definition: dotnet/NETGeographicLib/Geohash.cpp:69
main
int main(int argc, char **argv)
Definition: cmake/example_cmake_find_gtsam/main.cpp:63
NETGeographicLib::Geohash::Reverse
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)
Definition: dotnet/NETGeographicLib/Geohash.cpp:34
Geohash.hpp
Header for GeographicLib::Geohash class.
out
std::ofstream out("Result.txt")
std
Definition: BFloat16.h:88
args
Definition: pytypes.h:2210
NETGeographicLib::Geohash::Forward
static void Forward(double lat, double lon, int len, [System::Runtime::InteropServices::Out] System::String^% geohash)
Definition: dotnet/NETGeographicLib/Geohash.cpp:19
NETGeographicLib::Geohash::Geohash
Geohash()
Definition: Geohash.h:38
len
size_t len(handle h)
Get the length of a Python object.
Definition: pytypes.h:2446
lon
static const double lon
Definition: testGeographicLib.cpp:34
max
#define max(a, b)
Definition: datatypes.h:20
NETGeographicLib
Definition: Accumulator.h:13
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
lat
static const double lat
Definition: testGeographicLib.cpp:34


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:25:00