GeographicLib  1.46
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.
106  * @param[in] k0 central scale factor.
107  * @exception GeographicErr if \e a, (1 &minus; \e f) \e a, or \e k0 is
108  * not positive.
109  **********************************************************************/
110  TransverseMercator(real a, real f, real k0);
111
112  /**
113  * Forward projection, from geographic to transverse Mercator.
114  *
115  * @param[in] lon0 central meridian of the projection (degrees).
116  * @param[in] lat latitude of point (degrees).
117  * @param[in] lon longitude of point (degrees).
118  * @param[out] x easting of point (meters).
119  * @param[out] y northing of point (meters).
120  * @param[out] gamma meridian convergence at point (degrees).
121  * @param[out] k scale of projection at point.
122  *
123  * No false easting or northing is added. \e lat should be in the range
124  * [&minus;90&deg;, 90&deg;].
125  **********************************************************************/
126  void Forward(real lon0, real lat, real lon,
127  real& x, real& y, real& gamma, real& k) const;
128
129  /**
130  * Reverse projection, from transverse Mercator to geographic.
131  *
132  * @param[in] lon0 central meridian of the projection (degrees).
133  * @param[in] x easting of point (meters).
134  * @param[in] y northing of point (meters).
135  * @param[out] lat latitude of point (degrees).
136  * @param[out] lon longitude of point (degrees).
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. The value of \e lon returned is
141  * in the range [&minus;180&deg;, 180&deg;).
142  **********************************************************************/
143  void Reverse(real lon0, real x, real y,
144  real& lat, real& lon, real& gamma, real& k) const;
145
146  /**
147  * TransverseMercator::Forward without returning the convergence and scale.
148  **********************************************************************/
149  void Forward(real lon0, real lat, real lon,
150  real& x, real& y) const {
151  real gamma, k;
152  Forward(lon0, lat, lon, x, y, gamma, k);
153  }
154
155  /**
156  * TransverseMercator::Reverse without returning the convergence and scale.
157  **********************************************************************/
158  void Reverse(real lon0, real x, real y,
159  real& lat, real& lon) const {
160  real gamma, k;
161  Reverse(lon0, x, y, lat, lon, gamma, k);
162  }
163
164  /** \name Inspector functions
165  **********************************************************************/
166  ///@{
167  /**
168  * @return \e a the equatorial radius of the ellipsoid (meters). This is
169  * the value used in the constructor.
170  **********************************************************************/
171  Math::real MajorRadius() const { return _a; }
172
173  /**
174  * @return \e f the flattening of the ellipsoid. This is the value used in
175  * the constructor.
176  **********************************************************************/
177  Math::real Flattening() const { return _f; }
178
179  /**
180  * @return \e k0 central scale for the projection. This is the value of \e
181  * k0 used in the constructor and is the scale on the central meridian.
182  **********************************************************************/
183  Math::real CentralScale() const { return _k0; }
184  ///@}
185
186  /**
187  * A global instantiation of TransverseMercator with the WGS84 ellipsoid
188  * and the UTM scale factor. However, unlike UTM, no false easting or
189  * northing is added.
190  **********************************************************************/
191  static const TransverseMercator& UTM();
192  };
193
194 } // namespace GeographicLib
195
196 #endif // GEOGRAPHICLIB_TRANSVERSEMERCATOR_HPP
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:90
GeographicLib::Math::real real
Definition: GeodSolve.cpp:31
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.