GeographicLib
1.21
|
00001 /** 00002 * \file TransverseMercatorExact.hpp 00003 * \brief Header for GeographicLib::TransverseMercatorExact class 00004 * 00005 * Copyright (c) Charles Karney (2008-2011) <charles@karney.com> and licensed 00006 * under the MIT/X11 License. For more information, see 00007 * http://geographiclib.sourceforge.net/ 00008 **********************************************************************/ 00009 00010 #if !defined(GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP) 00011 #define GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP \ 00012 "$Id: bd96340b9dc3e7bfd09d4374296a75f4c6e00fc3 $" 00013 00014 #include <GeographicLib/Constants.hpp> 00015 #include <GeographicLib/EllipticFunction.hpp> 00016 00017 namespace GeographicLib { 00018 00019 /** 00020 * \brief An exact implementation of the Transverse Mercator Projection 00021 * 00022 * Implementation of the Transverse Mercator Projection given in 00023 * - L. P. Lee, 00024 * <a href="http://dx.doi.org/10.3138/X687-1574-4325-WM62"> Conformal 00025 * Projections Based On Jacobian Elliptic Functions</a>, Part V of 00026 * Conformal Projections Based on Elliptic Functions, 00027 * (B. V. Gutsell, Toronto, 1976), 128pp., 00028 * ISBN: 0919870163 00029 * (also appeared as: 00030 * Monograph 16, Suppl. No. 1 to Canadian Cartographer, Vol 13). 00031 * - C. F. F. Karney, 00032 * <a href="http://dx.doi.org/10.1007/s00190-011-0445-3"> 00033 * Transverse Mercator with an accuracy of a few nanometers,</a> 00034 * J. Geodesy 85(8), 475-485 (Aug. 2011); 00035 * preprint 00036 * <a href="http://arxiv.org/abs/1002.1417">arXiv:1002.1417</a>. 00037 * 00038 * Lee gives the correct results for forward and reverse transformations 00039 * subject to the branch cut rules (see the description of the \e extendp 00040 * argument to the constructor). The maximum error is about 8 nm (8 00041 * nanometers), ground distance, for the forward and reverse transformations. 00042 * The error in the convergence is 2e-15", the relative error in the 00043 * scale is 7e-12%%. See Sec. 3 of 00044 * <a href="http://arxiv.org/abs/1002.1417">arXiv:1002.1417</a> for details. 00045 * The method is "exact" in the sense that the errors are close to the 00046 * round-off limit and that no changes are needed in the algorithms for them 00047 * to be used with reals of a higher precision. Thus the errors using long 00048 * double (with a 64-bit fraction) are about 2000 times smaller than using 00049 * double (with a 53-bit fraction). 00050 * 00051 * This algorithm is about 4.5 times slower than the 6th-order Krüger 00052 * method, TransverseMercator, taking about 11 us for a combined forward and 00053 * reverse projection on a 2.66 GHz Intel machine (g++, version 4.3.0, -O3). 00054 * 00055 * The ellipsoid parameters and the central scale are set in the constructor. 00056 * The central meridian (which is a trivial shift of the longitude) is 00057 * specified as the \e lon0 argument of the TransverseMercatorExact::Forward 00058 * and TransverseMercatorExact::Reverse functions. The latitude of origin is 00059 * taken to be the equator. See the documentation on TransverseMercator for 00060 * how to include a false easting, false northing, or a latitude of origin. 00061 * 00062 * See <a href="http://geographiclib.sourceforge.net/tm-grid.kmz" 00063 * type="application/vnd.google-earth.kmz"> tm-grid.kmz</a>, for an 00064 * illustration of the transverse Mercator grid in Google Earth. 00065 * 00066 * See TransverseMercatorExact.cpp for more information on the 00067 * implementation. 00068 * 00069 * See \ref transversemercator for a discussion of this projection. 00070 * 00071 * Example of use: 00072 * \include example-TransverseMercatorExact.cpp 00073 * 00074 * <a href="TransverseMercatorProj.1.html">TransverseMercatorProj</a> is a 00075 * command-line utility providing access to the functionality of 00076 * TransverseMercator and TransverseMercatorExact. 00077 **********************************************************************/ 00078 00079 class GEOGRAPHIC_EXPORT TransverseMercatorExact { 00080 private: 00081 typedef Math::real real; 00082 static const real tol_; 00083 static const real tol1_; 00084 static const real tol2_; 00085 static const real taytol_; 00086 static const real overflow_; 00087 static const int numit_ = 10; 00088 real _a, _f, _k0, _mu, _mv, _e, _ep2; 00089 bool _extendp; 00090 EllipticFunction _Eu, _Ev; 00091 // tan(x) for x in [-pi/2, pi/2] ensuring that the sign is right 00092 static inline real tanx(real x) throw() { 00093 real t = std::tan(x); 00094 // Write the tests this way to ensure that tanx(NaN()) is NaN() 00095 return x >= 0 ? (!(t < 0) ? t : overflow_) : (!(t >= 0) ? t : -overflow_); 00096 } 00097 00098 real taup(real tau) const throw(); 00099 real taupinv(real taup) const throw(); 00100 00101 void zeta(real u, real snu, real cnu, real dnu, 00102 real v, real snv, real cnv, real dnv, 00103 real& taup, real& lam) const throw(); 00104 00105 void dwdzeta(real u, real snu, real cnu, real dnu, 00106 real v, real snv, real cnv, real dnv, 00107 real& du, real& dv) const throw(); 00108 00109 bool zetainv0(real psi, real lam, real& u, real& v) const throw(); 00110 void zetainv(real taup, real lam, real& u, real& v) const throw(); 00111 00112 void sigma(real u, real snu, real cnu, real dnu, 00113 real v, real snv, real cnv, real dnv, 00114 real& xi, real& eta) const throw(); 00115 00116 void dwdsigma(real u, real snu, real cnu, real dnu, 00117 real v, real snv, real cnv, real dnv, 00118 real& du, real& dv) const throw(); 00119 00120 bool sigmainv0(real xi, real eta, real& u, real& v) const throw(); 00121 void sigmainv(real xi, real eta, real& u, real& v) const throw(); 00122 00123 void Scale(real tau, real lam, 00124 real snu, real cnu, real dnu, 00125 real snv, real cnv, real dnv, 00126 real& gamma, real& k) const throw(); 00127 00128 public: 00129 00130 /** 00131 * Constructor for a ellipsoid with 00132 * 00133 * @param[in] a equatorial radius (meters). 00134 * @param[in] f flattening of ellipsoid. If \e f > 1, set flattening 00135 * to 1/\e f. 00136 * @param[in] k0 central scale factor. 00137 * @param[in] extendp use extended domain. 00138 * 00139 * The transverse Mercator projection has a branch point singularity at \e 00140 * lat = 0 and \e lon - \e lon0 = 90 (1 - \e e) or (for 00141 * TransverseMercatorExact::UTM) x = 18381 km, y = 0m. The \e extendp 00142 * argument governs where the branch cut is placed. With \e extendp = 00143 * false, the "standard" convention is followed, namely the cut is placed 00144 * along x > 18381 km, y = 0m. Forward can be called with any \e lat and 00145 * \e lon then produces the transformation shown in Lee, Fig 46. Reverse 00146 * analytically continues this in the +/- \e x direction. As a 00147 * consequence, Reverse may map multiple points to the same geographic 00148 * location; for example, for TransverseMercatorExact::UTM, \e x = 00149 * 22051449.037349 m, \e y = -7131237.022729 m and \e x = 29735142.378357 00150 * m, \e y = 4235043.607933 m both map to \e lat = -2 deg, \e lon = 88 deg. 00151 * 00152 * With \e extendp = true, the branch cut is moved to the lower left 00153 * quadrant. The various symmetries of the transverse Mercator projection 00154 * can be used to explore the projection on any sheet. In this mode the 00155 * domains of \e lat, \e lon, \e x, and \e y are restricted to 00156 * - the union of 00157 * - \e lat in [0, 90] and \e lon - \e lon0 in [0, 90] 00158 * - \e lat in (-90, 0] and \e lon - \e lon0 in [90 (1 - \e e), 90] 00159 * - the union of 00160 * - <i>x</i>/(\e k0 \e a) in [0, inf) and 00161 * <i>y</i>/(\e k0 \e a) in [0, E(<i>e</i><sup>2</sup>)] 00162 * - <i>x</i>/(\e k0 \e a) in [K(1 - <i>e</i><sup>2</sup>) - E(1 - 00163 * <i>e</i><sup>2</sup>), inf) and <i>y</i>/(\e k0 \e a) in (-inf, 0] 00164 * . 00165 * See Sec. 5 of 00166 * <a href="http://arxiv.org/abs/1002.1417">arXiv:1002.1417</a> for a full 00167 * discussion of the treatment of the branch cut. 00168 * 00169 * The method will work for all ellipsoids used in terrestrial geodesy. 00170 * The method cannot be applied directly to the case of a sphere (\e f = 0) 00171 * because some the constants characterizing this method diverge in that 00172 * limit, and in practice, \e f should be larger than about numeric_limits< 00173 * real >::%epsilon(). However, TransverseMercator treats the sphere 00174 * exactly. An exception is thrown if either axis of the ellipsoid or \e 00175 * k0 is not positive or if \e f <= 0. 00176 **********************************************************************/ 00177 TransverseMercatorExact(real a, real f, real k0, bool extendp = false); 00178 00179 /** 00180 * Forward projection, from geographic to transverse Mercator. 00181 * 00182 * @param[in] lon0 central meridian of the projection (degrees). 00183 * @param[in] lat latitude of point (degrees). 00184 * @param[in] lon longitude of point (degrees). 00185 * @param[out] x easting of point (meters). 00186 * @param[out] y northing of point (meters). 00187 * @param[out] gamma meridian convergence at point (degrees). 00188 * @param[out] k scale of projection at point. 00189 * 00190 * No false easting or northing is added. \e lat should be in the range 00191 * [-90, 90]; \e lon and \e lon0 should be in the range [-180, 360]. 00192 **********************************************************************/ 00193 void Forward(real lon0, real lat, real lon, 00194 real& x, real& y, real& gamma, real& k) const throw(); 00195 00196 /** 00197 * Reverse projection, from transverse Mercator to geographic. 00198 * 00199 * @param[in] lon0 central meridian of the projection (degrees). 00200 * @param[in] x easting of point (meters). 00201 * @param[in] y northing of point (meters). 00202 * @param[out] lat latitude of point (degrees). 00203 * @param[out] lon longitude of point (degrees). 00204 * @param[out] gamma meridian convergence at point (degrees). 00205 * @param[out] k scale of projection at point. 00206 * 00207 * No false easting or northing is added. \e lon0 should be in the range 00208 * [-180, 360]. The value of \e lon returned is in the range [-180, 180). 00209 **********************************************************************/ 00210 void Reverse(real lon0, real x, real y, 00211 real& lat, real& lon, real& gamma, real& k) const throw(); 00212 00213 /** 00214 * TransverseMercatorExact::Forward without returning the convergence and 00215 * scale. 00216 **********************************************************************/ 00217 void Forward(real lon0, real lat, real lon, 00218 real& x, real& y) const throw() { 00219 real gamma, k; 00220 Forward(lon0, lat, lon, x, y, gamma, k); 00221 } 00222 00223 /** 00224 * TransverseMercatorExact::Reverse without returning the convergence and 00225 * scale. 00226 **********************************************************************/ 00227 void Reverse(real lon0, real x, real y, 00228 real& lat, real& lon) const throw() { 00229 real gamma, k; 00230 Reverse(lon0, x, y, lat, lon, gamma, k); 00231 } 00232 00233 /** \name Inspector functions 00234 **********************************************************************/ 00235 ///@{ 00236 /** 00237 * @return \e a the equatorial radius of the ellipsoid (meters). This is 00238 * the value used in the constructor. 00239 **********************************************************************/ 00240 Math::real MajorRadius() const throw() { return _a; } 00241 00242 /** 00243 * @return \e f the flattening of the ellipsoid. This is the value used in 00244 * the constructor. 00245 **********************************************************************/ 00246 Math::real Flattening() const throw() { return _f; } 00247 00248 /// \cond SKIP 00249 /** 00250 * <b>DEPRECATED</b> 00251 * @return \e r the inverse flattening of the ellipsoid. 00252 **********************************************************************/ 00253 Math::real InverseFlattening() const throw() { return 1/_f; } 00254 /// \endcond 00255 00256 /** 00257 * @return \e k0 central scale for the projection. This is the value of \e 00258 * k0 used in the constructor and is the scale on the central meridian. 00259 **********************************************************************/ 00260 Math::real CentralScale() const throw() { return _k0; } 00261 ///@} 00262 00263 /** 00264 * A global instantiation of TransverseMercatorExact with the WGS84 00265 * ellipsoid and the UTM scale factor. However, unlike UTM, no false 00266 * easting or northing is added. 00267 **********************************************************************/ 00268 static const TransverseMercatorExact UTM; 00269 }; 00270 00271 } // namespace GeographicLib 00272 00273 #endif // GEOGRAPHICLIB_TRANSVERSEMERCATOREXACT_HPP