GeographicLib  1.44
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-2015) <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="https://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="https://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 &times; 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  *
52  * There's a singularity in the projection at &phi; = 0&deg;, &lambda;
53  * &minus; &lambda;<sub>0</sub> = &plusmn;(1 &minus; \e e)90&deg; (&asymp;
54  * &plusmn;82.6&deg; for the WGS84 ellipsoid), where \e e is the
55  * eccentricity. Beyond this point, the series ceases to converge and the
56  * results from this method will be garbage. To be on the safe side, don't
57  * use this method if the angular distance from the central meridian exceeds
58  * (1 &minus; 2e)90&deg; (&asymp; 75&deg; for the WGS84 ellipsoid)
59  *
60  * TransverseMercatorExact is an alternative implementation of the projection
61  * using exact formulas which yield accurate (to 8 nm) results over the
62  * entire ellipsoid.
63  *
64  * The ellipsoid parameters and the central scale are set in the constructor.
65  * The central meridian (which is a trivial shift of the longitude) is
66  * specified as the \e lon0 argument of the TransverseMercator::Forward and
67  * TransverseMercator::Reverse functions. The latitude of origin is taken to
68  * be the equator. There is no provision in this class for specifying a
69  * false easting or false northing or a different latitude of origin.
70  * However these are can be simply included by the calling function. For
71  * example, the UTMUPS class applies the false easting and false northing for
72  * the UTM projections. A more complicated example is the British National
73  * Grid (<a href="http://www.spatialreference.org/ref/epsg/7405/">
74  * EPSG:7405</a>) which requires the use of a latitude of origin. This is
75  * implemented by the GeographicLib::OSGB class.
76  *
77  * See TransverseMercator.cpp for more information on the implementation.
78  *
79  * See \ref transversemercator for a discussion of this projection.
80  *
81  * Example of use:
82  * \include example-TransverseMercator.cpp
83  *
84  * <a href="TransverseMercatorProj.1.html">TransverseMercatorProj</a> is a
85  * command-line utility providing access to the functionality of
86  * TransverseMercator and TransverseMercatorExact.
87  **********************************************************************/
88 
90  private:
91  typedef Math::real real;
92  static const int maxpow_ = GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER;
93  static const int numit_ = 5;
94  real _a, _f, _k0, _e2, _es, _e2m, _c, _n;
95  // _alp[0] and _bet[0] unused
96  real _a1, _b1, _alp[maxpow_ + 1], _bet[maxpow_ + 1];
97  friend class Ellipsoid; // For access to taupf, tauf.
98  public:
99 
100  /**
101  * Constructor for a ellipsoid with
102  *
103  * @param[in] a equatorial radius (meters).
104  * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
105  * Negative \e f gives a prolate ellipsoid. If \e f &gt; 1, set
106  * flattening to 1/\e f.
107  * @param[in] k0 central scale factor.
108  * @exception GeographicErr if \e a, (1 &minus; \e f) \e a, or \e k0 is
109  * not positive.
110  **********************************************************************/
111  TransverseMercator(real a, real f, real k0);
112 
113  /**
114  * Forward projection, from geographic to transverse Mercator.
115  *
116  * @param[in] lon0 central meridian of the projection (degrees).
117  * @param[in] lat latitude of point (degrees).
118  * @param[in] lon longitude of point (degrees).
119  * @param[out] x easting of point (meters).
120  * @param[out] y northing of point (meters).
121  * @param[out] gamma meridian convergence at point (degrees).
122  * @param[out] k scale of projection at point.
123  *
124  * No false easting or northing is added. \e lat should be in the range
125  * [&minus;90&deg;, 90&deg;].
126  **********************************************************************/
127  void Forward(real lon0, real lat, real lon,
128  real& x, real& y, real& gamma, real& k) const;
129 
130  /**
131  * Reverse projection, from transverse Mercator to geographic.
132  *
133  * @param[in] lon0 central meridian of the projection (degrees).
134  * @param[in] x easting of point (meters).
135  * @param[in] y northing of point (meters).
136  * @param[out] lat latitude of point (degrees).
137  * @param[out] lon longitude of point (degrees).
138  * @param[out] gamma meridian convergence at point (degrees).
139  * @param[out] k scale of projection at point.
140  *
141  * No false easting or northing is added. The value of \e lon returned is
142  * in the range [&minus;180&deg;, 180&deg;).
143  **********************************************************************/
144  void Reverse(real lon0, real x, real y,
145  real& lat, real& lon, real& gamma, real& k) const;
146 
147  /**
148  * TransverseMercator::Forward without returning the convergence and scale.
149  **********************************************************************/
150  void Forward(real lon0, real lat, real lon,
151  real& x, real& y) const {
152  real gamma, k;
153  Forward(lon0, lat, lon, x, y, gamma, k);
154  }
155 
156  /**
157  * TransverseMercator::Reverse without returning the convergence and scale.
158  **********************************************************************/
159  void Reverse(real lon0, real x, real y,
160  real& lat, real& lon) const {
161  real gamma, k;
162  Reverse(lon0, x, y, lat, lon, gamma, k);
163  }
164 
165  /** \name Inspector functions
166  **********************************************************************/
167  ///@{
168  /**
169  * @return \e a the equatorial radius of the ellipsoid (meters). This is
170  * the value used in the constructor.
171  **********************************************************************/
172  Math::real MajorRadius() const { return _a; }
173 
174  /**
175  * @return \e f the flattening of the ellipsoid. This is the value used in
176  * the constructor.
177  **********************************************************************/
178  Math::real Flattening() const { return _f; }
179 
180  /// \cond SKIP
181  /**
182  * <b>DEPRECATED</b>
183  * @return \e r the inverse flattening of the ellipsoid.
184  **********************************************************************/
185  Math::real InverseFlattening() const { return 1/_f; }
186  /// \endcond
187 
188  /**
189  * @return \e k0 central scale for the projection. This is the value of \e
190  * k0 used in the constructor and is the scale on the central meridian.
191  **********************************************************************/
192  Math::real CentralScale() const { return _k0; }
193  ///@}
194 
195  /**
196  * A global instantiation of TransverseMercator with the WGS84 ellipsoid
197  * and the UTM scale factor. However, unlike UTM, no false easting or
198  * northing is added.
199  **********************************************************************/
200  static const TransverseMercator& UTM();
201  };
202 
203 } // namespace GeographicLib
204 
205 #endif // GEOGRAPHICLIB_TRANSVERSEMERCATOR_HPP
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:90
GeographicLib::Math::real real
Definition: GeodSolve.cpp:32
Transverse Mercator projection.
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
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
#define GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER
Properties of an ellipsoid.
Definition: Ellipsoid.hpp:39
Header for GeographicLib::Constants class.