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

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

#include <NETGeographicLib/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 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)
 
static double Resolution (int prec)
 
static int Precision (double res)
 

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:

using namespace System;
using namespace NETGeographicLib;
int main(array<System::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, gars);
Console::WriteLine(String::Format("Precision: {0} GARS: {1}", prec, gars));
}
}
{
// Sample reverse calculation
String^ gars = gcnew String("381NH45");
double lat, lon;
for (int len = 5; len <= gars->Length; ++len) {
int prec;
GARS::Reverse(gars->Substring(0, len), lat, lon, 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));
return 1;
}
return 0;
}

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()

static void NETGeographicLib::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".

◆ Reverse()

static void NETGeographicLib::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.

◆ Resolution()

static double NETGeographicLib::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].

◆ Precision()

static int NETGeographicLib::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].


The documentation for this class was generated from the following file: