Static Public Member Functions | Private Types | Private Member Functions | Static Private Attributes | List of all members
GeographicLib::GARS Class Reference

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

#include <GARS.hpp>

Static Public Member Functions

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

Private Types

enum  {
  lonorig_ = -180, latorig_ = -90, baselon_ = 10, baselat_ = 24,
  lonlen_ = 3, latlen_ = 2, baselen_ = lonlen_ + latlen_, mult1_ = 2,
  mult2_ = 2, mult3_ = 3, m_ = mult1_ * mult2_ * mult3_, maxprec_ = 2,
  maxlen_ = baselen_ + maxprec_
}
 
typedef Math::real real
 

Private Member Functions

 GARS ()
 

Static Private Attributes

static const char *const digits_ = "0123456789"
 
static const char *const letters_ = "ABCDEFGHJKLMNPQRSTUVWXYZ"
 

Detailed Description

Conversions for the Global Area Reference System (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.

Example of use:

// 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;
}
}

Definition at line 38 of file GARS.hpp.

Member Typedef Documentation

Definition at line 40 of file GARS.hpp.

Member Enumeration Documentation

anonymous enum
private
Enumerator
lonorig_ 
latorig_ 
baselon_ 
baselat_ 
lonlen_ 
latlen_ 
baselen_ 
mult1_ 
mult2_ 
mult3_ 
m_ 
maxprec_ 
maxlen_ 

Definition at line 43 of file GARS.hpp.

Constructor & Destructor Documentation

GeographicLib::GARS::GARS ( )
private

Member Function Documentation

void GeographicLib::GARS::Forward ( real  lat,
real  lon,
int  prec,
std::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°].
std::bad_allocif 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 20 of file src/GARS.cpp.

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

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 127 of file GARS.hpp.

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

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 113 of file GARS.hpp.

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]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 57 of file src/GARS.cpp.

Member Data Documentation

const char *const GeographicLib::GARS::digits_ = "0123456789"
staticprivate

Definition at line 41 of file GARS.hpp.

const char *const GeographicLib::GARS::letters_ = "ABCDEFGHJKLMNPQRSTUVWXYZ"
staticprivate

Definition at line 42 of file GARS.hpp.


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


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:57:59