GeographicLib 2.1.2
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-2022) <charles@karney.com> and licensed
6 * under the MIT/X11 License. For more information, see
7 * https://geographiclib.sourceforge.io/
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
25namespace 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://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://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="https://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="https://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="https://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 * This class also returns the meridian convergence \e gamma and scale \e k.
78 * The meridian convergence is the bearing of grid north (the \e y axis)
79 * measured clockwise from true north.
80 *
81 * See TransverseMercator.cpp for more information on the implementation.
82 *
83 * See \ref transversemercator for a discussion of this projection.
84 *
85 * Example of use:
86 * \include example-TransverseMercator.cpp
87 *
88 * <a href="TransverseMercatorProj.1.html">TransverseMercatorProj</a> is a
89 * command-line utility providing access to the functionality of
90 * TransverseMercator and TransverseMercatorExact.
91 **********************************************************************/
92
94 private:
95 typedef Math::real real;
96 static const int maxpow_ = GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER;
97 static const int numit_ = 5;
98 real _a, _f, _k0, _e2, _es, _e2m, _c, _n;
99 // _alp[0] and _bet[0] unused
100 real _a1, _b1, _alp[maxpow_ + 1], _bet[maxpow_ + 1];
101 friend class Ellipsoid; // For access to taupf, tauf.
102 public:
103
104 /**
105 * Constructor for an ellipsoid with
106 *
107 * @param[in] a equatorial radius (meters).
108 * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
109 * Negative \e f gives a prolate ellipsoid.
110 * @param[in] k0 central scale factor.
111 * @exception GeographicErr if \e a, (1 &minus; \e f) \e a, or \e k0 is
112 * not positive.
113 **********************************************************************/
114 TransverseMercator(real a, real f, real k0);
115
116 /**
117 * Forward projection, from geographic to transverse Mercator.
118 *
119 * @param[in] lon0 central meridian of the projection (degrees).
120 * @param[in] lat latitude of point (degrees).
121 * @param[in] lon longitude of point (degrees).
122 * @param[out] x easting of point (meters).
123 * @param[out] y northing of point (meters).
124 * @param[out] gamma meridian convergence at point (degrees).
125 * @param[out] k scale of projection at point.
126 *
127 * No false easting or northing is added. \e lat should be in the range
128 * [&minus;90&deg;, 90&deg;].
129 **********************************************************************/
130 void Forward(real lon0, real lat, real lon,
131 real& x, real& y, real& gamma, real& k) const;
132
133 /**
134 * Reverse projection, from transverse Mercator to geographic.
135 *
136 * @param[in] lon0 central meridian of the projection (degrees).
137 * @param[in] x easting of point (meters).
138 * @param[in] y northing of point (meters).
139 * @param[out] lat latitude of point (degrees).
140 * @param[out] lon longitude of point (degrees).
141 * @param[out] gamma meridian convergence at point (degrees).
142 * @param[out] k scale of projection at point.
143 *
144 * No false easting or northing is added. The value of \e lon returned is
145 * in the range [&minus;180&deg;, 180&deg;].
146 **********************************************************************/
147 void Reverse(real lon0, real x, real y,
148 real& lat, real& lon, real& gamma, real& k) const;
149
150 /**
151 * TransverseMercator::Forward without returning the convergence and scale.
152 **********************************************************************/
153 void Forward(real lon0, real lat, real lon,
154 real& x, real& y) const {
155 real gamma, k;
156 Forward(lon0, lat, lon, x, y, gamma, k);
157 }
158
159 /**
160 * TransverseMercator::Reverse without returning the convergence and scale.
161 **********************************************************************/
162 void Reverse(real lon0, real x, real y,
163 real& lat, real& lon) const {
164 real gamma, k;
165 Reverse(lon0, x, y, lat, lon, gamma, k);
166 }
167
168 /** \name Inspector functions
169 **********************************************************************/
170 ///@{
171 /**
172 * @return \e a the equatorial radius of the ellipsoid (meters). This is
173 * the value used in the constructor.
174 **********************************************************************/
175 Math::real EquatorialRadius() const { return _a; }
176
177 /**
178 * @return \e f the flattening of the ellipsoid. This is the value used in
179 * the constructor.
180 **********************************************************************/
181 Math::real Flattening() const { return _f; }
182
183 /**
184 * @return \e k0 central scale for the projection. This is the value of \e
185 * k0 used in the constructor and is the scale on the central meridian.
186 **********************************************************************/
187 Math::real CentralScale() const { return _k0; }
188 ///@}
189
190 /**
191 * A global instantiation of TransverseMercator with the WGS84 ellipsoid
192 * and the UTM scale factor. However, unlike UTM, no false easting or
193 * northing is added.
194 **********************************************************************/
195 static const TransverseMercator& UTM();
196 };
197
198} // namespace GeographicLib
199
200#endif // GEOGRAPHICLIB_TRANSVERSEMERCATOR_HPP
Header for GeographicLib::Constants class.
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:67
GeographicLib::Math::real real
Definition: GeodSolve.cpp:31
#define GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER
Properties of an ellipsoid.
Definition: Ellipsoid.hpp:39
Transverse Mercator projection.
void Reverse(real lon0, real x, real y, real &lat, real &lon) const
void Forward(real lon0, real lat, real lon, real &x, real &y) const
Namespace for GeographicLib.
Definition: Accumulator.cpp:12