examples/example-TransverseMercator.cpp
Go to the documentation of this file.
1 // Example of using the GeographicLib::TransverseMercator class
2 
3 #include <iostream>
4 #include <iomanip>
5 #include <exception>
7 
8 using namespace std;
9 using namespace GeographicLib;
10 
11 // Define a UTM projection for an arbitrary ellipsoid
12 class UTMalt {
13 private:
14  TransverseMercator _tm; // The projection
15  double _lon0; // Central longitude
16  double _falseeasting, _falsenorthing;
17 public:
18  UTMalt(double a, // equatorial radius
19  double f, // flattening
20  int zone, // the UTM zone + hemisphere
21  bool northp)
22  : _tm(a, f, Constants::UTM_k0())
23  , _lon0(6 * zone - 183)
24  , _falseeasting(5e5)
25  , _falsenorthing(northp ? 0 : 100e5) {
26  if (!(zone >= 1 && zone <= 60))
27  throw GeographicErr("zone not in [1,60]");
28  }
29  void Forward(double lat, double lon, double& x, double& y) {
30  _tm.Forward(_lon0, lat, lon, x, y);
31  x += _falseeasting;
32  y += _falsenorthing;
33  }
34  void Reverse(double x, double y, double& lat, double& lon) {
35  x -= _falseeasting;
36  y -= _falsenorthing;
37  _tm.Reverse(_lon0, x, y, lat, lon);
38  }
39 };
40 
41 int main() {
42  try {
43  UTMalt tm(6378388, 1/297.0, 30, true); // International ellipsoid, zone 30n
44  {
45  // Sample forward calculation
46  double lat = 40.4, lon = -3.7; // Madrid
47  double x, y;
48  tm.Forward(lat, lon, x, y);
49  cout << fixed << setprecision(0) << x << " " << y << "\n";
50  }
51  {
52  // Sample reverse calculation
53  double x = 441e3, y = 4472e3;
54  double lat, lon;
55  tm.Reverse(x, y, lat, lon);
56  cout << fixed << setprecision(5) << lat << " " << lon << "\n";
57  }
58  }
59  catch (const exception& e) {
60  cerr << "Caught exception: " << e.what() << "\n";
61  return 1;
62  }
63 }
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GeographicLib
Namespace for GeographicLib.
Definition: JacobiConformal.hpp:15
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
UTMalt::_tm
TransverseMercator _tm
Definition: examples/example-TransverseMercator.cpp:14
main
int main()
Definition: examples/example-TransverseMercator.cpp:41
UTMalt::_falsenorthing
double _falsenorthing
Definition: examples/example-TransverseMercator.cpp:16
GeographicLib::GeographicErr
Exception handling for GeographicLib.
Definition: Constants.hpp:389
UTMalt::UTMalt
UTMalt(double a, double f, int zone, bool northp)
Definition: examples/example-TransverseMercator.cpp:18
TransverseMercator.hpp
Header for GeographicLib::TransverseMercator class.
UTMalt::Reverse
void Reverse(double x, double y, double &lat, double &lon)
Definition: examples/example-TransverseMercator.cpp:34
GeographicLib::TransverseMercator::Forward
void Forward(real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
Definition: src/TransverseMercator.cpp:350
UTMalt::_lon0
double _lon0
Definition: examples/example-TransverseMercator.cpp:15
y
Scalar * y
Definition: level1_cplx_impl.h:124
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
UTMalt
Definition: examples/example-TransverseMercator.cpp:12
std
Definition: BFloat16.h:88
GeographicLib::TransverseMercator::Reverse
void Reverse(real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
Definition: src/TransverseMercator.cpp:516
lon
static const double lon
Definition: testGeographicLib.cpp:34
UTMalt::Forward
void Forward(double lat, double lon, double &x, double &y)
Definition: examples/example-TransverseMercator.cpp:29
GeographicLib::TransverseMercator
Transverse Mercator projection.
Definition: TransverseMercator.hpp:93
GeographicLib::Constants
Constants needed by GeographicLib
Definition: Constants.hpp:131
lat
static const double lat
Definition: testGeographicLib.cpp:34


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:31