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

.NET Wrapper for GeographicLib::GARS More...

#include <GARS.h>

Public Member Functions

 GARS ()
 

Static Public Member Functions

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

Detailed Description

.NET Wrapper for GeographicLib::GARS

This class allows .NET applications to access GeographicLib::GARS.

The Global Area Reference System is described in

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

C# Example:

using System;
namespace example_GARS
{
class Program
{
static void Main(string[] args)
{
try {
{
// Sample forward calculation
double lat = 57.64911, lon = 10.40744; // Jutland
string gars;
for (int prec = 0; prec <= 2; ++prec) {
GARS.Forward(lat, lon, prec, out gars);
Console.WriteLine(String.Format("Precision: {0} GARS: {1}", prec, gars));
}
}
{
// Sample reverse calculation
string gars = "381NH45";
double lat, lon;
for (int len = 5; len <= gars.Length; ++len) {
int prec;
GARS.Reverse(gars.Substring(0, len), 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 gars;
for (int prec = 0; prec <= 2; ++prec) {
GARS::Forward(lat, lon, prec, gars);
cout << prec << " " << gars << "\n";
}
}
{
// Sample reverse calculation
string gars = "381NH45";
double lat, lon;
cout << fixed;
for (int len = 5; len <= int(gars.size()); ++len) {
int prec;
GARS::Reverse(gars.substr(0, len), 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_GARS
Sub Main()
Try
' Sample forward calculation
Dim lat As Double = 57.64911, lon = 10.40744
Dim garstring As String
For prec As Integer = 0 To 2
GARS.Forward(lat, lon, prec, garstring)
Console.WriteLine(String.Format("Precision: {0} GARS: {1}", prec, garstring))
Next
' Sample reverse calculation
garstring = "381NH45"
For len As Integer = 5 To garstring.Length
Dim prec As Integer
GARS.Reverse(garstring.Substring(0, len), lat, lon, prec, True)
Console.WriteLine(String.Format("Precision: {0} Latitude: {1} Longitude {2}", prec, 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 35 of file GARS.h.

Constructor & Destructor Documentation

◆ GARS()

NETGeographicLib::GARS::GARS ( )
inline

Definition at line 38 of file GARS.h.

Member Function Documentation

◆ Forward()

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

Convert from geographic coordinates to GARS.

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

prec specifies the precision of gars as follows:

  • prec = 0 (min), 30' precision, e.g., 006AG;
  • prec = 1, 15' precision, e.g., 006AG3;
  • prec = 2 (max), 5' precision, e.g., 006AG39.

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

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

◆ Precision()

int GARS::Precision ( double  res)
static

The GARS precision required to meet a given geographic resolution.

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

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

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

◆ Resolution()

double GARS::Resolution ( int  prec)
static

The angular resolution of a GARS.

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

Internally, prec is first put in the range [0, 2].

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

◆ Reverse()

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

Convert from GARS to geographic coordinates.

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

The case of the letters in gars is ignored. prec is in the range [0, 2] and gives the precision of gars as follows:

  • prec = 0 (min), 30' precision, e.g., 006AG;
  • prec = 1, 15' precision, e.g., 006AG3;
  • prec = 2 (max), 5' precision, e.g., 006AG39.

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

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


The documentation for this class was generated from the following files:
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
GARS.hpp
Header for GeographicLib::GARS 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::GARS::GARS
GARS()
Definition: GARS.h:38
NETGeographicLib::GARS::Forward
static void Forward(double lat, double lon, int prec, [System::Runtime::InteropServices::Out] System::String^% gars)
Definition: dotnet/NETGeographicLib/GARS.cpp:19
out
std::ofstream out("Result.txt")
NETGeographicLib::GARS::Reverse
static void Reverse(System::String^ gars, [System::Runtime::InteropServices::Out] double% lat, [System::Runtime::InteropServices::Out] double% lon, [System::Runtime::InteropServices::Out] int% prec, bool centerp)
Definition: dotnet/NETGeographicLib/GARS.cpp:34
std
Definition: BFloat16.h:88
args
Definition: pytypes.h:2210
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
NETGeographicLib
Definition: Accumulator.h:13
lat
static const double lat
Definition: testGeographicLib.cpp:34


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:16:46