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

.NET wrapper for GeographicLib::Georef. More...

#include <Georef.h>

Static Public Member Functions

static void Forward (double lat, double lon, int prec, [System::Runtime::InteropServices::Out] System::String^% georef)
 
static int Precision (double res)
 
static double Resolution (int prec)
 
static void Reverse (System::String^ georef, [System::Runtime::InteropServices::Out] double% lat, [System::Runtime::InteropServices::Out] double% lon, [System::Runtime::InteropServices::Out] int% prec, bool centerp)
 

Private Member Functions

 Georef ()
 

Detailed Description

.NET wrapper for GeographicLib::Georef.

The World Geographic Reference System is described in

It provides a compact string representation of a geographic area (expressed as latitude and longitude). The classes GARS and Geohash implement similar compact representations.

C# Example:

using System;
namespace example_Georef
{
class Program
{
static void Main(string[] args)
{
try {
{
// Sample forward calculation
double lat = 57.64911, lon = 10.40744; // Jutland
string georef;
for (int prec = -1; prec <= 11; ++prec) {
Georef.Forward(lat, lon, prec, out georef);
Console.WriteLine(String.Format("Precision: {0} Georef: {1}", prec, georef));
}
}
{
// Sample reverse calculation
string georef = "NKLN2444638946";
double lat, lon;
int prec;
Georef.Reverse(georef.Substring(0, 2), out lat, out lon, out prec, true);
Console.WriteLine(String.Format("Precision: {0} Latitude: {1} Longitude: {2}", prec, lat, lon));
Georef.Reverse(georef.Substring(0, 4), out lat, out lon, out prec, true);
Console.WriteLine(String.Format("Precision: {0} Latitude: {1} Longitude: {2}", prec, lat, lon));
Georef.Reverse(georef, out lat, out lon, out prec, true);
Console.WriteLine(String.Format("Precision: {0} Latitude: {1} Longitude: {2}", prec, lat, lon));
}
}
catch (GeographicErr e) {
Console.WriteLine(String.Format("Caught Exception {0}", e.Message));
}
}
}
}

Managed C++ Example:

// Example of using the GeographicLib::GARS 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
string georef;
for (int prec = -1; prec <= 11; ++prec) {
Georef::Forward(lat, lon, prec, georef);
cout << prec << " " << georef << "\n";
}
}
{
// Sample reverse calculation
string georef = "NKLN2444638946";
double lat, lon;
int prec;
cout << fixed;
Georef::Reverse(georef.substr(0, 2), lat, lon, prec);
cout << prec << " " << lat << " " << lon << "\n";
Georef::Reverse(georef.substr(0, 4), lat, lon, prec);
cout << prec << " " << lat << " " << lon << "\n";
Georef::Reverse(georef, lat, lon, prec);
cout << prec << " " << lat << " " << lon << "\n";
}
}
catch (const exception& e) {
cerr << "Caught exception: " << e.what() << "\n";
return 1;
}
}

Visual Basic Example:

Imports NETGeographicLib
Module example_Georef
Sub Main()
Try
' Sample forward calculation
Dim lat As Double = 57.64911, lon = 10.40744 ' Jutland
Dim georefstring As String
For prec1 As Integer = -1 To 11
Georef.Forward(lat, lon, prec1, georefstring)
Console.WriteLine(String.Format("Precision: {0} Georef: {1}", prec1, georefstring))
Next
' Sample reverse calculation
georefstring = "NKLN2444638946"
Dim prec As Integer
Georef.Reverse(georefstring.Substring(0, 2), lat, lon, prec, True)
Console.WriteLine(String.Format("Precision: {0} Latitude: {1} Longitude: {2}", prec, lat, lon))
Georef.Reverse(georefstring.Substring(0, 4), lat, lon, prec, True)
Console.WriteLine(String.Format("Precision: {0} Latitude: {1} Longitude: {2}", prec, lat, lon))
Georef.Reverse(georefstring, lat, lon, prec, True)
Console.WriteLine(String.Format("Precision: {0} Latitude: {1} Longitude: {2}", prec, lat, lon))
Catch ex As GeographicErr
Console.WriteLine(String.Format("Caught Exception {0}", ex.Message))
End Try
End Sub
End Module

Definition at line 33 of file Georef.h.

Constructor & Destructor Documentation

◆ Georef()

NETGeographicLib::Georef::Georef ( )
inlineprivate

Definition at line 37 of file Georef.h.

Member Function Documentation

◆ Forward()

void Georef::Forward ( double  lat,
double  lon,
int  prec,
[System::Runtime::InteropServices::Out] System::String^%  georef 
)
static

Convert from geographic coordinates to georef.

Parameters
[in]latlatitude of point (degrees).
[in]lonlongitude of point (degrees).
[in]precthe precision of the resulting georef.
[out]georefthe georef string.
Exceptions
GeographicErrif lat is not in [−90°, 90°] or if memory for georef can't be allocated.

prec specifies the precision of georef as follows:

  • prec = −1 (min), 15°
  • prec = 0, 1°
  • prec = 1, converted to prec = 2
  • prec = 2, 1'
  • prec = 3, 0.1'
  • prec = 4, 0.01'
  • prec = 5, 0.001'
  • prec = 11 (max), 10−9'

If lat or lon is NaN, then georef is set to "INVALID".

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

◆ Precision()

int Georef::Precision ( double  res)
static

The Georef precision required to meet a given geographic resolution.

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

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

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

◆ Resolution()

double Georef::Resolution ( int  prec)
static

The angular resolution of a Georef.

Parameters
[in]precthe precision of the Georef.
Returns
the latitude-longitude resolution (degrees).

Internally, prec is first put in the range [−1, 11].

Definition at line 54 of file dotnet/NETGeographicLib/Georef.cpp.

◆ Reverse()

void Georef::Reverse ( System::String^  georef,
[System::Runtime::InteropServices::Out] double%  lat,
[System::Runtime::InteropServices::Out] double%  lon,
[System::Runtime::InteropServices::Out] int prec,
bool  centerp 
)
static

Convert from Georef to geographic coordinates.

Parameters
[in]georefthe Georef.
[out]latlatitude of point (degrees).
[out]lonlongitude of point (degrees).
[out]precthe precision of georef.
[in]centerpif true (the default) return the center georef, otherwise return the south-west corner.
Exceptions
GeographicErrif georef is illegal.

The case of the letters in georef is ignored. prec is in the range [−1, 11] and gives the precision of georef as follows:

  • prec = −1 (min), 15°
  • prec = 0, 1°
  • prec = 1, not returned
  • prec = 2, 1'
  • prec = 3, 0.1'
  • prec = 4, 0.01'
  • prec = 5, 0.001'
  • prec = 11 (max), 10−9'

If the first 3 characters of georef are "INV", then lat and lon are set to NaN and prec is unchanged.

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


The documentation for this class was generated from the following files:
Georef.hpp
Header for GeographicLib::Georef class.
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GeographicLib
Namespace for GeographicLib.
Definition: JacobiConformal.hpp:15
main
int main(int argc, char **argv)
Definition: cmake/example_cmake_find_gtsam/main.cpp:63
NETGeographicLib::Georef::Forward
static void Forward(double lat, double lon, int prec, [System::Runtime::InteropServices::Out] System::String^% georef)
Definition: dotnet/NETGeographicLib/Georef.cpp:19
NETGeographicLib::Georef::Reverse
static void Reverse(System::String^ georef, [System::Runtime::InteropServices::Out] double% lat, [System::Runtime::InteropServices::Out] double% lon, [System::Runtime::InteropServices::Out] int% prec, bool centerp)
Definition: dotnet/NETGeographicLib/Georef.cpp:34
NETGeographicLib::Georef::Georef
Georef()
Definition: Georef.h:37
out
std::ofstream out("Result.txt")
std
Definition: BFloat16.h:88
args
Definition: pytypes.h:2210
lon
static const double lon
Definition: testGeographicLib.cpp:34
NETGeographicLib
Definition: Accumulator.h:13
lat
static const double lat
Definition: testGeographicLib.cpp:34


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