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