TransverseMercatorExact.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /**
  2. * \file TransverseMercatorExact.hpp
  3. * \brief Header for GeographicLib::TransverseMercatorExact class
  4. *
  5. * Copyright (c) Charles Karney (2008-2020) <charles@karney.com> and licensed
  6. * under the MIT/X11 License. For more information, see
  7. * https://geographiclib.sourceforge.io/
  8. **********************************************************************/
  9. #if !defined(GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP)
  10. #define GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP 1
  11. #include <GeographicLib/Constants.hpp>
  12. #include <GeographicLib/EllipticFunction.hpp>
  13. namespace GeographicLib {
  14. /**
  15. * \brief An exact implementation of the transverse Mercator projection
  16. *
  17. * Implementation of the Transverse Mercator Projection given in
  18. * - L. P. Lee,
  19. * <a href="https://doi.org/10.3138/X687-1574-4325-WM62"> Conformal
  20. * Projections Based On Jacobian Elliptic Functions</a>, Part V of
  21. * Conformal Projections Based on Elliptic Functions,
  22. * (B. V. Gutsell, Toronto, 1976), 128pp.,
  23. * ISBN: 0919870163
  24. * (also appeared as:
  25. * Monograph 16, Suppl. No. 1 to Canadian Cartographer, Vol 13).
  26. * - C. F. F. Karney,
  27. * <a href="https://doi.org/10.1007/s00190-011-0445-3">
  28. * Transverse Mercator with an accuracy of a few nanometers,</a>
  29. * J. Geodesy 85(8), 475--485 (Aug. 2011);
  30. * preprint
  31. * <a href="https://arxiv.org/abs/1002.1417">arXiv:1002.1417</a>.
  32. *
  33. * Lee gives the correct results for forward and reverse transformations
  34. * subject to the branch cut rules (see the description of the \e extendp
  35. * argument to the constructor). The maximum error is about 8 nm (8
  36. * nanometers), ground distance, for the forward and reverse transformations.
  37. * The error in the convergence is 2 &times; 10<sup>&minus;15</sup>&quot;,
  38. * the relative error in the scale is 7 &times; 10<sup>&minus;12</sup>%%.
  39. * See Sec. 3 of
  40. * <a href="https://arxiv.org/abs/1002.1417">arXiv:1002.1417</a> for details.
  41. * The method is "exact" in the sense that the errors are close to the
  42. * round-off limit and that no changes are needed in the algorithms for them
  43. * to be used with reals of a higher precision. Thus the errors using long
  44. * double (with a 64-bit fraction) are about 2000 times smaller than using
  45. * double (with a 53-bit fraction).
  46. *
  47. * This algorithm is about 4.5 times slower than the 6th-order Kr&uuml;ger
  48. * method, TransverseMercator, taking about 11 us for a combined forward and
  49. * reverse projection on a 2.66 GHz Intel machine (g++, version 4.3.0, -O3).
  50. *
  51. * The ellipsoid parameters and the central scale are set in the constructor.
  52. * The central meridian (which is a trivial shift of the longitude) is
  53. * specified as the \e lon0 argument of the TransverseMercatorExact::Forward
  54. * and TransverseMercatorExact::Reverse functions. The latitude of origin is
  55. * taken to be the equator. See the documentation on TransverseMercator for
  56. * how to include a false easting, false northing, or a latitude of origin.
  57. *
  58. * See <a href="https://geographiclib.sourceforge.io/tm-grid.kmz"
  59. * type="application/vnd.google-earth.kmz"> tm-grid.kmz</a>, for an
  60. * illustration of the transverse Mercator grid in Google Earth.
  61. *
  62. * This class also returns the meridian convergence \e gamma and scale \e k.
  63. * The meridian convergence is the bearing of grid north (the \e y axis)
  64. * measured clockwise from true north.
  65. *
  66. * See TransverseMercatorExact.cpp for more information on the
  67. * implementation.
  68. *
  69. * See \ref transversemercator for a discussion of this projection.
  70. *
  71. * Example of use:
  72. * \include example-TransverseMercatorExact.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. class GEOGRAPHICLIB_EXPORT TransverseMercatorExact {
  79. private:
  80. typedef Math::real real;
  81. static const int numit_ = 10;
  82. real tol_, tol2_, taytol_;
  83. real _a, _f, _k0, _mu, _mv, _e;
  84. bool _extendp;
  85. EllipticFunction _Eu, _Ev;
  86. void zeta(real u, real snu, real cnu, real dnu,
  87. real v, real snv, real cnv, real dnv,
  88. real& taup, real& lam) const;
  89. void dwdzeta(real u, real snu, real cnu, real dnu,
  90. real v, real snv, real cnv, real dnv,
  91. real& du, real& dv) const;
  92. bool zetainv0(real psi, real lam, real& u, real& v) const;
  93. void zetainv(real taup, real lam, real& u, real& v) const;
  94. void sigma(real u, real snu, real cnu, real dnu,
  95. real v, real snv, real cnv, real dnv,
  96. real& xi, real& eta) const;
  97. void dwdsigma(real u, real snu, real cnu, real dnu,
  98. real v, real snv, real cnv, real dnv,
  99. real& du, real& dv) const;
  100. bool sigmainv0(real xi, real eta, real& u, real& v) const;
  101. void sigmainv(real xi, real eta, real& u, real& v) const;
  102. void Scale(real tau, real lam,
  103. real snu, real cnu, real dnu,
  104. real snv, real cnv, real dnv,
  105. real& gamma, real& k) const;
  106. public:
  107. /**
  108. * Constructor for a ellipsoid with
  109. *
  110. * @param[in] a equatorial radius (meters).
  111. * @param[in] f flattening of ellipsoid.
  112. * @param[in] k0 central scale factor.
  113. * @param[in] extendp use extended domain.
  114. * @exception GeographicErr if \e a, \e f, or \e k0 is not positive.
  115. *
  116. * The transverse Mercator projection has a branch point singularity at \e
  117. * lat = 0 and \e lon &minus; \e lon0 = 90 (1 &minus; \e e) or (for
  118. * TransverseMercatorExact::UTM) x = 18381 km, y = 0m. The \e extendp
  119. * argument governs where the branch cut is placed. With \e extendp =
  120. * false, the "standard" convention is followed, namely the cut is placed
  121. * along \e x > 18381 km, \e y = 0m. Forward can be called with any \e lat
  122. * and \e lon then produces the transformation shown in Lee, Fig 46.
  123. * Reverse analytically continues this in the &plusmn; \e x direction. As
  124. * a consequence, Reverse may map multiple points to the same geographic
  125. * location; for example, for TransverseMercatorExact::UTM, \e x =
  126. * 22051449.037349 m, \e y = &minus;7131237.022729 m and \e x =
  127. * 29735142.378357 m, \e y = 4235043.607933 m both map to \e lat =
  128. * &minus;2&deg;, \e lon = 88&deg;.
  129. *
  130. * With \e extendp = true, the branch cut is moved to the lower left
  131. * quadrant. The various symmetries of the transverse Mercator projection
  132. * can be used to explore the projection on any sheet. In this mode the
  133. * domains of \e lat, \e lon, \e x, and \e y are restricted to
  134. * - the union of
  135. * - \e lat in [0, 90] and \e lon &minus; \e lon0 in [0, 90]
  136. * - \e lat in (-90, 0] and \e lon &minus; \e lon0 in [90 (1 &minus; \e
  137. e), 90]
  138. * - the union of
  139. * - <i>x</i>/(\e k0 \e a) in [0, &infin;) and
  140. * <i>y</i>/(\e k0 \e a) in [0, E(<i>e</i><sup>2</sup>)]
  141. * - <i>x</i>/(\e k0 \e a) in [K(1 &minus; <i>e</i><sup>2</sup>) &minus;
  142. * E(1 &minus; <i>e</i><sup>2</sup>), &infin;) and <i>y</i>/(\e k0 \e
  143. * a) in (&minus;&infin;, 0]
  144. * .
  145. * See Sec. 5 of
  146. * <a href="https://arxiv.org/abs/1002.1417">arXiv:1002.1417</a> for a full
  147. * discussion of the treatment of the branch cut.
  148. *
  149. * The method will work for all ellipsoids used in terrestrial geodesy.
  150. * The method cannot be applied directly to the case of a sphere (\e f = 0)
  151. * because some the constants characterizing this method diverge in that
  152. * limit, and in practice, \e f should be larger than about
  153. * numeric_limits<real>::epsilon(). However, TransverseMercator treats the
  154. * sphere exactly.
  155. **********************************************************************/
  156. TransverseMercatorExact(real a, real f, real k0, bool extendp = false);
  157. /**
  158. * Forward projection, from geographic to transverse Mercator.
  159. *
  160. * @param[in] lon0 central meridian of the projection (degrees).
  161. * @param[in] lat latitude of point (degrees).
  162. * @param[in] lon longitude of point (degrees).
  163. * @param[out] x easting of point (meters).
  164. * @param[out] y northing of point (meters).
  165. * @param[out] gamma meridian convergence at point (degrees).
  166. * @param[out] k scale of projection at point.
  167. *
  168. * No false easting or northing is added. \e lat should be in the range
  169. * [&minus;90&deg;, 90&deg;].
  170. **********************************************************************/
  171. void Forward(real lon0, real lat, real lon,
  172. real& x, real& y, real& gamma, real& k) const;
  173. /**
  174. * Reverse projection, from transverse Mercator to geographic.
  175. *
  176. * @param[in] lon0 central meridian of the projection (degrees).
  177. * @param[in] x easting of point (meters).
  178. * @param[in] y northing of point (meters).
  179. * @param[out] lat latitude of point (degrees).
  180. * @param[out] lon longitude of point (degrees).
  181. * @param[out] gamma meridian convergence at point (degrees).
  182. * @param[out] k scale of projection at point.
  183. *
  184. * No false easting or northing is added. The value of \e lon returned is
  185. * in the range [&minus;180&deg;, 180&deg;].
  186. **********************************************************************/
  187. void Reverse(real lon0, real x, real y,
  188. real& lat, real& lon, real& gamma, real& k) const;
  189. /**
  190. * TransverseMercatorExact::Forward without returning the convergence and
  191. * scale.
  192. **********************************************************************/
  193. void Forward(real lon0, real lat, real lon,
  194. real& x, real& y) const {
  195. real gamma, k;
  196. Forward(lon0, lat, lon, x, y, gamma, k);
  197. }
  198. /**
  199. * TransverseMercatorExact::Reverse without returning the convergence and
  200. * scale.
  201. **********************************************************************/
  202. void Reverse(real lon0, real x, real y,
  203. real& lat, real& lon) const {
  204. real gamma, k;
  205. Reverse(lon0, x, y, lat, lon, gamma, k);
  206. }
  207. /** \name Inspector functions
  208. **********************************************************************/
  209. ///@{
  210. /**
  211. * @return \e a the equatorial radius of the ellipsoid (meters). This is
  212. * the value used in the constructor.
  213. **********************************************************************/
  214. Math::real EquatorialRadius() const { return _a; }
  215. /**
  216. * @return \e f the flattening of the ellipsoid. This is the value used in
  217. * the constructor.
  218. **********************************************************************/
  219. Math::real Flattening() const { return _f; }
  220. /**
  221. * @return \e k0 central scale for the projection. This is the value of \e
  222. * k0 used in the constructor and is the scale on the central meridian.
  223. **********************************************************************/
  224. Math::real CentralScale() const { return _k0; }
  225. /**
  226. * \deprecated An old name for EquatorialRadius().
  227. **********************************************************************/
  228. GEOGRAPHICLIB_DEPRECATED("Use EquatorialRadius()")
  229. Math::real MajorRadius() const { return EquatorialRadius(); }
  230. ///@}
  231. /**
  232. * A global instantiation of TransverseMercatorExact with the WGS84
  233. * ellipsoid and the UTM scale factor. However, unlike UTM, no false
  234. * easting or northing is added.
  235. **********************************************************************/
  236. static const TransverseMercatorExact& UTM();
  237. };
  238. } // namespace GeographicLib
  239. #endif // GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP