File: example-Georef.cpp

package info (click to toggle)
geographiclib 2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,572 kB
  • sloc: cpp: 27,765; sh: 5,463; makefile: 695; python: 12; ansic: 10
file content (41 lines) | stat: -rw-r--r-- 1,109 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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;
  }
}