GeographicLib: GeographicLib::Georef Class Reference

GeographicLib 2.5.2

Loading...
Searching...
No Matches
GeographicLib::Georef Class Reference

Conversions for the World Geographic Reference System (georef) More...

`#include <GeographicLib/Georef.hpp>`

## Static Public Member Functions
static void | Forward (real lat, real lon, int prec, std::string &georef)
static void | Reverse (const std::string &georef, 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 World Geographic Reference System (georef)

The World Geographic Reference System is described in

- https://en.wikipedia.org/wiki/Georef
- https://web.archive.org/web/20161214054445/http://earth-info.nga.mil/GandG/coordsys/grids/georef.pdf

It provides a compact string representation of a geographic area (expressed as latitude and longitude). The classes GARS 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/Georef.hpp>
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;
}
}
main
int main(int argc, const char *const argv[])
Definition CartConvert.cpp:28
Georef.hpp
Header for GeographicLib::Georef class.
GeographicLib::Georef::Forward
static void Forward(real lat, real lon, int prec, std::string &georef)
Definition Georef.cpp:22
GeographicLib::Georef::Reverse
static void Reverse(const std::string &georef, real &lat, real &lon, int &prec, bool centerp=true)
Definition Georef.cpp:65
GeographicLib
Namespace for GeographicLib.
Definition Accumulator.cpp:12
std
Definition NearestNeighbor.hpp:806

Definition at line 32 of file Georef.hpp.

## Member Function Documentation

## ◆ Forward()

void GeographicLib::Georef::Forward | ( | real | lat,
|  | real | lon,
|  | int | prec,
|  | std::string & | georef )
| static

Convert from geographic coordinates to georef.

Parameters

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

Exceptions

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

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

## ◆ Reverse()

void GeographicLib::Georef::Reverse | ( | const std::string & | georef,
|  | real & | lat,
|  | real & | lon,
|  | int & | prec,
|  | bool | centerp = true )
| static

Convert from Georef to geographic coordinates.

Parameters

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

Exceptions

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

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

## ◆ Resolution()

Math::real GeographicLib::Georef::Resolution | ( | int | prec | ) |
| inlinestatic

The angular resolution of a Georef.

Parameters

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

Returns
  the latitude-longitude resolution (degrees).

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

Definition at line 113 of file Georef.hpp.

Referenced by Precision().

## ◆ Precision()

int GeographicLib::Georef::Precision | ( | real | res | ) |
| inlinestatic

The Georef precision required to meet a given geographic resolution.

Parameters

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

Returns
  Georef precision.

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

Definition at line 134 of file Georef.hpp.

References Resolution().

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

- Georef.hpp
- Georef.cpp