GeographicLib 2.5
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-2023) <karney@alum.mit.edu> 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
15
16#if !defined(GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER)
17/**
18 * The order of the series approximation used in TransverseMercator.
19 * GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER can be set to any integer in [4, 8].
20 **********************************************************************/
21# define GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER \
22 (GEOGRAPHICLIB_PRECISION == 2 ? 6 : \
23 (GEOGRAPHICLIB_PRECISION == 1 ? 4 : 8))
24#endif
25
26namespace GeographicLib {
27
28 /**
29 * \brief Transverse Mercator projection
30 *
31 * This uses Kr&uuml;ger's method which evaluates the projection and its
32 * inverse in terms of a series. See
33 * - L. Kr&uuml;ger,
34 * <a href="https://doi.org/10.2312/GFZ.b103-krueger28"> Konforme
35 * Abbildung des Erdellipsoids in der Ebene</a> (Conformal mapping of the
36 * ellipsoidal earth to the plane), Royal Prussian Geodetic Institute, New
37 * Series 52, 172 pp. (1912).
38 * - C. F. F. Karney,
39 * <a href="https://doi.org/10.1007/s00190-011-0445-3">
40 * Transverse Mercator with an accuracy of a few nanometers,</a>
41 * J. Geodesy 85(8), 475--485 (Aug. 2011);
42 * preprint
43 * <a href="https://arxiv.org/abs/1002.1417">arXiv:1002.1417</a>.
44 *
45 * Kr&uuml;ger's method has been extended from 4th to 6th order. The maximum
46 * error is 5 nm (5 nanometers), ground distance, for all positions within 35
47 * degrees of the central meridian. The error in the convergence is 2
48 * &times; 10<sup>&minus;15</sup>&quot; and the relative error in the scale
49 * is 6 &times; 10<sup>&minus;12</sup>%%. See Sec. 4 of
50 * <a href="https://arxiv.org/abs/1002.1417">arXiv:1002.1417</a> for details.
51 * The speed penalty in going to 6th order is only about 1%.
52 *
53 * There's a singularity in the projection at &phi; = 0&deg;, &lambda;
54 * &minus; &lambda;<sub>0</sub> = &plusmn;(1 &minus; \e e)90&deg; (&asymp;
55 * &plusmn;82.6&deg; for the WGS84 ellipsoid), where \e e is the
56 * eccentricity. Beyond this point, the series ceases to converge and the
57 * results from this method will be garbage. To be on the safe side, don't
58 * use this method if the angular distance from the central meridian exceeds
59 * (1 &minus; 2e)90&deg; (&asymp; 75&deg; for the WGS84 ellipsoid)
60 *
61 * TransverseMercatorExact is an alternative implementation of the projection
62 * using exact formulas which yield accurate (to 8 nm) results over the
63 * entire ellipsoid. This formulation is accessible in this class by calling
64 * the constructor with \e exact = true.
65 *
66 * The ellipsoid parameters and the central scale are set in the constructor.
67 * The central meridian (which is a trivial shift of the longitude) is
68 * specified as the \e lon0 argument of the TransverseMercator::Forward and
69 * TransverseMercator::Reverse functions. The latitude of origin is taken to
70 * be the equator. There is no provision in this class for specifying a
71 * false easting or false northing or a different latitude of origin.
72 * However these are can be simply included by the calling function. For
73 * example, the UTMUPS class applies the false easting and false northing for
74 * the UTM projections. A more complicated example is the British National
75 * Grid (<a href="https://www.spatialreference.org/ref/epsg/7405/">
76 * EPSG:7405</a>) which requires the use of a latitude of origin. This is
77 * implemented by the GeographicLib::OSGB class.
78 *
79 * This class also returns the meridian convergence \e gamma and scale \e k.
80 * The meridian convergence is the bearing of grid north (the \e y axis)
81 * measured clockwise from true north.
82 *
83 * See TransverseMercator.cpp for more information on the implementation.
84 *
85 * See \ref transversemercator for a discussion of this projection.
86 *
87 * Example of use:
88 * \include example-TransverseMercator.cpp
89 *
90 * <a href="TransverseMercatorProj.1.html">TransverseMercatorProj</a> is a
91 * command-line utility providing access to the functionality of this class.
92 **********************************************************************/
93
95 private:
96 typedef Math::real real;
97 static const int maxpow_ = GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER;
98 static const int numit_ = 5;
99 real _a, _f, _k0;
100 bool _exact;
101 real _e2, _es, _e2m, _c, _n;
102 // _alp[0] and _bet[0] unused
103 real _a1, _b1, _alp[maxpow_ + 1], _bet[maxpow_ + 1];
105 public:
106
107 /**
108 * Constructor for an ellipsoid with
109 *
110 * @param[in] a equatorial radius (meters).
111 * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
112 * Negative \e f gives a prolate ellipsoid.
113 * @param[in] k0 central scale factor.
114 * @param[in] exact if true use exact formulation in terms of elliptic
115 * functions instead of series expansions (default false).
116 * @param[in] extendp use extended domain (default false); should only be
117 * used if \e exact = true;
118 * @exception GeographicErr if \e a, (1 &minus; \e f) \e a, or \e k0 is
119 * not positive.
120 *
121 * With \e exact = true, this class delegates the calculations to the
122 * TransverseMercatorExact classes which compute the projection in terms of
123 * elliptic functions.
124 **********************************************************************/
125 TransverseMercator(real a, real f, real k0,
126 bool exact = false, bool extendp = false);
127
128 /**
129 * Forward projection, from geographic to transverse Mercator.
130 *
131 * @param[in] lon0 central meridian of the projection (degrees).
132 * @param[in] lat latitude of point (degrees).
133 * @param[in] lon longitude of point (degrees).
134 * @param[out] x easting of point (meters).
135 * @param[out] y northing of point (meters).
136 * @param[out] gamma meridian convergence at point (degrees).
137 * @param[out] k scale of projection at point.
138 *
139 * No false easting or northing is added. \e lat should be in the range
140 * [&minus;90&deg;, 90&deg;].
141 **********************************************************************/
142 void Forward(real lon0, real lat, real lon,
143 real& x, real& y, real& gamma, real& k) const;
144
145 /**
146 * Reverse projection, from transverse Mercator to geographic.
147 *
148 * @param[in] lon0 central meridian of the projection (degrees).
149 * @param[in] x easting of point (meters).
150 * @param[in] y northing of point (meters).
151 * @param[out] lat latitude of point (degrees).
152 * @param[out] lon longitude of point (degrees).
153 * @param[out] gamma meridian convergence at point (degrees).
154 * @param[out] k scale of projection at point.
155 *
156 * No false easting or northing is added. The value of \e lon returned is
157 * in the range [&minus;180&deg;, 180&deg;].
158 **********************************************************************/
159 void Reverse(real lon0, real x, real y,
160 real& lat, real& lon, real& gamma, real& k) const;
161
162 /**
163 * TransverseMercator::Forward without returning the convergence and scale.
164 **********************************************************************/
165 void Forward(real lon0, real lat, real lon,
166 real& x, real& y) const {
167 real gamma, k;
168 Forward(lon0, lat, lon, x, y, gamma, k);
169 }
170
171 /**
172 * TransverseMercator::Reverse without returning the convergence and scale.
173 **********************************************************************/
174 void Reverse(real lon0, real x, real y,
175 real& lat, real& lon) const {
176 real gamma, k;
177 Reverse(lon0, x, y, lat, lon, gamma, k);
178 }
179
180 /** \name Inspector functions
181 **********************************************************************/
182 ///@{
183 /**
184 * @return \e a the equatorial radius of the ellipsoid (meters). This is
185 * the value used in the constructor.
186 **********************************************************************/
187 Math::real EquatorialRadius() const { return _a; }
188
189 /**
190 * @return \e f the flattening of the ellipsoid. This is the value used in
191 * the constructor.
192 **********************************************************************/
193 Math::real Flattening() const { return _f; }
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 * @return \e exact whether the exact formulation is used. This is the
203 * value used in the constructor.
204 **********************************************************************/
205 bool Exact() const { return _exact; }
206 ///@}
207
208 /**
209 * A global instantiation of TransverseMercator with the WGS84 ellipsoid
210 * and the UTM scale factor. However, unlike UTM, no false easting or
211 * northing is added.
212 **********************************************************************/
213 static const TransverseMercator& UTM();
214 };
215
216} // namespace GeographicLib
217
218#endif // GEOGRAPHICLIB_TRANSVERSEMERCATOR_HPP
Header for GeographicLib::Constants class.
#define GEOGRAPHICLIB_EXPORT
Definition Constants.hpp:67
GeographicLib::Math::real real
Definition GeodSolve.cpp:28
Header for GeographicLib::TransverseMercatorExact class.
#define GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER
An exact implementation of the transverse Mercator projection.
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.