GeographicLib::GARS Class Reference

Conversions for the Global Area Reference System (GARS) More...

`#include <GeographicLib/GARS.hpp>`

## Static Public Member Functions

static void | Forward (real lat, real lon, int prec, std::string &gars)
static void | Reverse (const std::string &gars, real &lat, real &lon, int &prec, bool centerp=true)
static Math::real | Resolution (int prec)
static int | Precision (real res)

## Detailed Description

Conversions for the Global Area Reference System (GARS)

The Global Area Reference System is described in

- https://en.wikipedia.org/wiki/Global_Area_Reference_System
- https://earth-info.nga.mil/index.php?dir=coordsys&action=coordsys#tab_gars

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

Example of use:

// Example of using the GeographicLib::GARS class
#include <iostream>
#include <iomanip>
#include <exception>
#include <string>
#include <GeographicLib/GARS.hpp>
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;
}
}
main
int main(int argc, const char *const argv[])
Definition: CartConvert.cpp:29
GARS.hpp
Header for GeographicLib::GARS class.
GeographicLib::GARS::Reverse
static void Reverse(const std::string &gars, real &lat, real &lon, int &prec, bool centerp=true)
Definition: GARS.cpp:65
GeographicLib::GARS::Forward
static void Forward(real lat, real lon, int prec, std::string &gars)
Definition: GARS.cpp:25
GeographicLib
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
std
Definition: NearestNeighbor.hpp:812

Definition at line 38 of file GARS.hpp.

## Member Function Documentation

## Forward()

void GeographicLib::GARS::Forward | ( | real | lat,
|  | real | lon,
|  | int | prec,
|  | std::string & | gars
| ) |  |

static

Convert from geographic coordinates to GARS.

Parameters

  [in] | lat | latitude of point (degrees).
  [in] | lon | longitude of point (degrees).
  [in] | prec | the precision of the resulting GARS.
  [out] | gars | the GARS string.

Exceptions

  GeographicErr | if lat is not in [−90°, 90°].
  std::bad_alloc | 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 25 of file GARS.cpp.

References GeographicLib::Math::AngNormalize(), GeographicLib::Math::hd, GeographicLib::Math::qd, and GeographicLib::Utility::str().

## Reverse()

void GeographicLib::GARS::Reverse | ( | const std::string & | gars,
|  | real & | lat,
|  | real & | lon,
|  | int & | prec,
|  | bool | centerp = `true`
| ) |  |

static

Convert from GARS to geographic coordinates.

Parameters

  [in] | gars | the GARS.
  [out] | lat | latitude of point (degrees).
  [out] | lon | longitude of point (degrees).
  [out] | prec | the precision of gars.
  [in] | centerp | if true (the default) return the center of the gars, otherwise return the south-west corner.

Exceptions

  GeographicErr | if 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 65 of file GARS.cpp.

References GeographicLib::Utility::lookup(), GeographicLib::Math::NaN(), and GeographicLib::Math::td.

## Resolution()

static Math::real GeographicLib::GARS::Resolution | ( | int | prec | ) |

inline static

The angular resolution of a GARS.

Parameters

  [in] | prec | the precision of the GARS.

Returns
  the latitude-longitude resolution (degrees).

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

Definition at line 113 of file GARS.hpp.

## Precision()

static int GeographicLib::GARS::Precision | ( | real | res | ) |

inline static

The GARS precision required to meet a given geographic resolution.

Parameters

  [in] | res | the minimum of resolution in latitude and longitude (degrees).

Returns
  GARS precision.

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

Definition at line 127 of file GARS.hpp.

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

- GARS.hpp
- GARS.cpp