GeographicLib  1.38
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TransverseMercator.hpp
Go to the documentation of this file.
1 /**
2  * \file TransverseMercator.hpp
3  * \brief Header for GeographicLib::TransverseMercator class
4  *
5  * Copyright (c) Charles Karney (2008-2014) <charles@karney.com> and licensed
6  * under the MIT/X11 License. For more information, see
7  * http://geographiclib.sourceforge.net/
8  **********************************************************************/
9 
10 #if !defined(GEOGRAPHICLIB_TRANSVERSEMERCATOR_HPP)
11 #define GEOGRAPHICLIB_TRANSVERSEMERCATOR_HPP 1
12 
14 
15 #if !defined(GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER)
16 /**
17  * The order of the series approximation used in TransverseMercator.
18  * GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER can be set to any integer in [4, 8].
19  **********************************************************************/
20 # define GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER \
21  (GEOGRAPHICLIB_PRECISION == 2 ? 6 : \
22  (GEOGRAPHICLIB_PRECISION == 1 ? 4 : 8))
23 #endif
24 
25 namespace GeographicLib {
26 
27  /**
28  * \brief Transverse Mercator projection
29  *
30  * This uses Kr&uuml;ger's method which evaluates the projection and its
31  * inverse in terms of a series. See
32  * - L. Kr&uuml;ger,
33  * <a href="http://dx.doi.org/10.2312/GFZ.b103-krueger28"> Konforme
34  * Abbildung des Erdellipsoids in der Ebene</a> (Conformal mapping of the
35  * ellipsoidal earth to the plane), Royal Prussian Geodetic Institute, New
36  * Series 52, 172 pp. (1912).
37  * - C. F. F. Karney,
38  * <a href="http://dx.doi.org/10.1007/s00190-011-0445-3">
39  * Transverse Mercator with an accuracy of a few nanometers,</a>
40  * J. Geodesy 85(8), 475--485 (Aug. 2011);
41  * preprint
42  * <a href="http://arxiv.org/abs/1002.1417">arXiv:1002.1417</a>.
43  *
44  * Kr&uuml;ger's method has been extended from 4th to 6th order. The maximum
45  * error is 5 nm (5 nanometers), ground distance, for all positions within 35
46  * degrees of the central meridian. The error in the convergence is 2
47  * &times; 10<sup>&minus;15</sup>&quot; and the relative error in the scale
48  * is 6 &minus; 10<sup>&minus;12</sup>%%. See Sec. 4 of
49  * <a href="http://arxiv.org/abs/1002.1417">arXiv:1002.1417</a> for details.
50  * The speed penalty in going to 6th order is only about 1%.
51  * TransverseMercatorExact is an alternative implementation of the projection
52  * using exact formulas which yield accurate (to 8 nm) results over the
53  * entire ellipsoid.
54  *
55  * The ellipsoid parameters and the central scale are set in the constructor.
56  * The central meridian (which is a trivial shift of the longitude) is
57  * specified as the \e lon0 argument of the TransverseMercator::Forward and
58  * TransverseMercator::Reverse functions. The latitude of origin is taken to
59  * be the equator. There is no provision in this class for specifying a
60  * false easting or false northing or a different latitude of origin.
61  * However these are can be simply included by the calling function. For
62  * example, the UTMUPS class applies the false easting and false northing for
63  * the UTM projections. A more complicated example is the British National
64  * Grid (<a href="http://www.spatialreference.org/ref/epsg/7405/">
65  * EPSG:7405</a>) which requires the use of a latitude of origin. This is
66  * implemented by the GeographicLib::OSGB class.
67  *
68  * See TransverseMercator.cpp for more information on the implementation.
69  *
70  * See \ref transversemercator for a discussion of this projection.
71  *
72  * Example of use:
73  * \include example-TransverseMercator.cpp
74  *
75  * <a href="TransverseMercatorProj.1.html">TransverseMercatorProj</a> is a
76  * command-line utility providing access to the functionality of
77  * TransverseMercator and TransverseMercatorExact.
78  **********************************************************************/
79 
81  private:
82  typedef Math::real real;
83  static const int maxpow_ = GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER;
84  static const int numit_ = 5;
85  real tol_;
86  real _a, _f, _k0, _e2, _e, _e2m, _c, _n;
87  // _alp[0] and _bet[0] unused
88  real _a1, _b1, _alp[maxpow_ + 1], _bet[maxpow_ + 1];
89  static inline real overflow() {
90  // Overflow value s.t. atan(overflow_) = pi/2
91  static const real
92  overflow = 1 / Math::sq(std::numeric_limits<real>::epsilon());
93  return overflow;
94  }
95  // tan(x) for x in [-pi/2, pi/2] ensuring that the sign is right
96  static inline real tanx(real x) {
97  using std::tan;
98  real t = tan(x);
99  // Write the tests this way to ensure that tanx(NaN()) is NaN()
100  return x >= 0 ?
101  (!(t < 0) ? t : overflow()) :
102  (!(t >= 0) ? t : -overflow());
103  }
104  // Return e * atanh(e * x) for f >= 0, else return
105  // - sqrt(-e2) * atan( sqrt(-e2) * x) for f < 0
106  inline real eatanhe(real x) const {
107  using std::atan;
108  return _f >= 0 ? _e * Math::atanh(_e * x) : - _e * atan(_e * x);
109  }
110  real taupf(real tau) const;
111  real tauf(real taup) const;
112 
113  friend class Ellipsoid; // For access to taupf, tauf.
114  public:
115 
116  /**
117  * Constructor for a ellipsoid with
118  *
119  * @param[in] a equatorial radius (meters).
120  * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
121  * Negative \e f gives a prolate ellipsoid. If \e f &gt; 1, set
122  * flattening to 1/\e f.
123  * @param[in] k0 central scale factor.
124  * @exception GeographicErr if \e a, (1 &minus; \e f) \e a, or \e k0 is
125  * not positive.
126  **********************************************************************/
127  TransverseMercator(real a, real f, real k0);
128 
129  /**
130  * Forward projection, from geographic to transverse Mercator.
131  *
132  * @param[in] lon0 central meridian of the projection (degrees).
133  * @param[in] lat latitude of point (degrees).
134  * @param[in] lon longitude of point (degrees).
135  * @param[out] x easting of point (meters).
136  * @param[out] y northing of point (meters).
137  * @param[out] gamma meridian convergence at point (degrees).
138  * @param[out] k scale of projection at point.
139  *
140  * No false easting or northing is added. \e lat should be in the range
141  * [&minus;90&deg;, 90&deg;]; \e lon and \e lon0 should be in the
142  * range [&minus;540&deg;, 540&deg;).
143  **********************************************************************/
144  void Forward(real lon0, real lat, real lon,
145  real& x, real& y, real& gamma, real& k) const;
146 
147  /**
148  * Reverse projection, from transverse Mercator to geographic.
149  *
150  * @param[in] lon0 central meridian of the projection (degrees).
151  * @param[in] x easting of point (meters).
152  * @param[in] y northing of point (meters).
153  * @param[out] lat latitude of point (degrees).
154  * @param[out] lon longitude of point (degrees).
155  * @param[out] gamma meridian convergence at point (degrees).
156  * @param[out] k scale of projection at point.
157  *
158  * No false easting or northing is added. \e lon0 should be in the range
159  * [&minus;540&deg;, 540&deg;). The value of \e lon returned is in
160  * the range [&minus;180&deg;, 180&deg;).
161  **********************************************************************/
162  void Reverse(real lon0, real x, real y,
163  real& lat, real& lon, real& gamma, real& k) const;
164 
165  /**
166  * TransverseMercator::Forward without returning the convergence and scale.
167  **********************************************************************/
168  void Forward(real lon0, real lat, real lon,
169  real& x, real& y) const {
170  real gamma, k;
171  Forward(lon0, lat, lon, x, y, gamma, k);
172  }
173 
174  /**
175  * TransverseMercator::Reverse without returning the convergence and scale.
176  **********************************************************************/
177  void Reverse(real lon0, real x, real y,
178  real& lat, real& lon) const {
179  real gamma, k;
180  Reverse(lon0, x, y, lat, lon, gamma, k);
181  }
182 
183  /** \name Inspector functions
184  **********************************************************************/
185  ///@{
186  /**
187  * @return \e a the equatorial radius of the ellipsoid (meters). This is
188  * the value used in the constructor.
189  **********************************************************************/
190  Math::real MajorRadius() const { return _a; }
191 
192  /**
193  * @return \e f the flattening of the ellipsoid. This is the value used in
194  * the constructor.
195  **********************************************************************/
196  Math::real Flattening() const { return _f; }
197 
198  /// \cond SKIP
199  /**
200  * <b>DEPRECATED</b>
201  * @return \e r the inverse flattening of the ellipsoid.
202  **********************************************************************/
203  Math::real InverseFlattening() const { return 1/_f; }
204  /// \endcond
205 
206  /**
207  * @return \e k0 central scale for the projection. This is the value of \e
208  * k0 used in the constructor and is the scale on the central meridian.
209  **********************************************************************/
210  Math::real CentralScale() const { return _k0; }
211  ///@}
212 
213  /**
214  * A global instantiation of TransverseMercator with the WGS84 ellipsoid
215  * and the UTM scale factor. However, unlike UTM, no false easting or
216  * northing is added.
217  **********************************************************************/
218  static const TransverseMercator& UTM();
219  };
220 
221 } // namespace GeographicLib
222 
223 #endif // GEOGRAPHICLIB_TRANSVERSEMERCATOR_HPP
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:70
GeographicLib::Math::real real
Definition: GeodSolve.cpp:40
Transverse Mercator projection.
static T atanh(T x)
Definition: Math.hpp:339
void Forward(real lon0, real lat, real lon, real &x, real &y) const
void Reverse(real lon0, real x, real y, real &lat, real &lon) const
static T sq(T x)
Definition: Math.hpp:243
#define GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER
Properties of an ellipsoid.
Definition: Ellipsoid.hpp:39
Header for GeographicLib::Constants class.