00001 /** 00002 * \file Constants.hpp 00003 * \brief Header for GeographicLib::Constants 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_CONSTANTS_HPP) 00011 #define GEOGRAPHICLIB_CONSTANTS_HPP 1 00012 00013 #include <GeographicLib/Config.h> 00014 00015 /** 00016 * @relates GeographicLib::Constants 00017 * Pack the version components into a single integer. 00018 **********************************************************************/ 00019 #define GEOGRAPHICLIB_VERSION_NUM(a,b,c) ((((a) * 10000 + (b)) * 100) + (c)) 00020 00021 /** 00022 * @relates GeographicLib::Constants 00023 * The version of GeographicLib as a single integer, packed as MMmmmmpp where 00024 * MM is the major version, mmmm is the minor version, and pp is the patch 00025 * level. 00026 **********************************************************************/ 00027 #define GEOGRAPHICLIB_VERSION \ 00028 GEOGRAPHICLIB_VERSION_NUM(GEOGRAPHICLIB_VERSION_MAJOR, \ 00029 GEOGRAPHICLIB_VERSION_MINOR, \ 00030 GEOGRAPHICLIB_VERSION_PATCH) 00031 00032 /** 00033 * @relates GeographicLib::Constants 00034 * A compile-time assert. Use C++11 static_assert, if available. 00035 **********************************************************************/ 00036 #if !defined(GEOGRAPHICLIB_STATIC_ASSERT) 00037 # if __cplusplus >= 201103 00038 # define GEOGRAPHICLIB_STATIC_ASSERT static_assert 00039 # elif defined(__GXX_EXPERIMENTAL_CXX0X__) 00040 # define GEOGRAPHICLIB_STATIC_ASSERT static_assert 00041 # elif defined(_MSC_VER) && _MSC_VER >= 1600 00042 // For reference, here is a table of Visual Studio and _MSC_VER 00043 // correspondences: 00044 // 00045 // _MSC_VER Visual Studio 00046 // 1300 vc7 00047 // 1311 vc7.1 (2003) 00048 // 1400 vc8 (2005) 00049 // 1500 vc9 (2008) 00050 // 1600 vc10 (2010) 00051 // 1700 vc11 (2012) 00052 // 1800 vc12 (2013) 00053 # define GEOGRAPHICLIB_STATIC_ASSERT static_assert 00054 # else 00055 # define GEOGRAPHICLIB_STATIC_ASSERT(cond,reason) \ 00056 { enum{ GEOGRAPHICLIB_STATIC_ASSERT_ENUM = 1/int(cond) }; } 00057 # endif 00058 #endif 00059 00060 #if defined(_MSC_VER) && defined(GEOGRAPHICLIB_SHARED_LIB) && \ 00061 GEOGRAPHICLIB_SHARED_LIB 00062 # if GEOGRAPHICLIB_SHARED_LIB > 1 00063 # error GEOGRAPHICLIB_SHARED_LIB must be 0 or 1 00064 # elif defined(GeographicLib_EXPORTS) 00065 # define GEOGRAPHICLIB_EXPORT __declspec(dllexport) 00066 # else 00067 # define GEOGRAPHICLIB_EXPORT __declspec(dllimport) 00068 # endif 00069 #else 00070 # define GEOGRAPHICLIB_EXPORT 00071 #endif 00072 00073 #include <stdexcept> 00074 #include <string> 00075 #include <GeographicLib/Math.hpp> 00076 00077 /** 00078 * \brief Namespace for %GeographicLib 00079 * 00080 * All of %GeographicLib is defined within the GeographicLib namespace. In 00081 * addition all the header files are included via %GeographicLib/Class.hpp. 00082 * This minimizes the likelihood of conflicts with other packages. 00083 **********************************************************************/ 00084 namespace GeographicLib { 00085 00086 /** 00087 * \brief %Constants needed by %GeographicLib 00088 * 00089 * Define constants specifying the WGS84 ellipsoid, the UTM and UPS 00090 * projections, and various unit conversions. 00091 * 00092 * Example of use: 00093 * \include example-Constants.cpp 00094 **********************************************************************/ 00095 class GEOGRAPHICLIB_EXPORT Constants { 00096 private: 00097 typedef Math::real real; 00098 Constants(); // Disable constructor 00099 00100 public: 00101 /** 00102 * A synonym for Math::degree<real>(). 00103 **********************************************************************/ 00104 static inline Math::real degree() { return Math::degree(); } 00105 /** 00106 * @return the number of radians in an arcminute. 00107 **********************************************************************/ 00108 static inline Math::real arcminute() 00109 { return Math::degree() / 60; } 00110 /** 00111 * @return the number of radians in an arcsecond. 00112 **********************************************************************/ 00113 static inline Math::real arcsecond() 00114 { return Math::degree() / 3600; } 00115 00116 /** \name Ellipsoid parameters 00117 **********************************************************************/ 00118 ///@{ 00119 /** 00120 * @tparam T the type of the returned value. 00121 * @return the equatorial radius of WGS84 ellipsoid (6378137 m). 00122 **********************************************************************/ 00123 template<typename T> static inline T WGS84_a() 00124 { return 6378137 * meter<T>(); } 00125 /** 00126 * A synonym for WGS84_a<real>(). 00127 **********************************************************************/ 00128 static inline Math::real WGS84_a() { return WGS84_a<real>(); } 00129 /** 00130 * @tparam T the type of the returned value. 00131 * @return the flattening of WGS84 ellipsoid (1/298.257223563). 00132 **********************************************************************/ 00133 template<typename T> static inline T WGS84_f() 00134 { return 1 / ( T(298257223563LL) / 1000000000 ); } 00135 /** 00136 * A synonym for WGS84_f<real>(). 00137 **********************************************************************/ 00138 static inline Math::real WGS84_f() { return WGS84_f<real>(); } 00139 /** 00140 * @tparam T the type of the returned value. 00141 * @return the gravitational constant of the WGS84 ellipsoid, \e GM, in 00142 * m<sup>3</sup> s<sup>−2</sup>. 00143 **********************************************************************/ 00144 template<typename T> static inline T WGS84_GM() 00145 { return T(3986004) * 100000000 + 41800000; } 00146 /** 00147 * A synonym for WGS84_GM<real>(). 00148 **********************************************************************/ 00149 static inline Math::real WGS84_GM() { return WGS84_GM<real>(); } 00150 /** 00151 * @tparam T the type of the returned value. 00152 * @return the angular velocity of the WGS84 ellipsoid, ω, in rad 00153 * s<sup>−1</sup>. 00154 **********************************************************************/ 00155 template<typename T> static inline T WGS84_omega() 00156 { return 7292115 / (T(1000000) * 100000); } 00157 /** 00158 * A synonym for WGS84_omega<real>(). 00159 **********************************************************************/ 00160 static inline Math::real WGS84_omega() { return WGS84_omega<real>(); } 00161 /// \cond SKIP 00162 /** 00163 * <b>DEPRECATED</b> 00164 * @return the reciprocal flattening of WGS84 ellipsoid. 00165 **********************************************************************/ 00166 template<typename T> static inline T WGS84_r() 00167 { return 1/WGS84_f<T>(); } 00168 /** 00169 * <b>DEPRECATED</b> 00170 * A synonym for WGS84_r<real>(). 00171 **********************************************************************/ 00172 static inline Math::real WGS84_r() { return WGS84_r<real>(); } 00173 /// \endcond 00174 /** 00175 * @tparam T the type of the returned value. 00176 * @return the equatorial radius of GRS80 ellipsoid, \e a, in m. 00177 **********************************************************************/ 00178 template<typename T> static inline T GRS80_a() 00179 { return 6378137 * meter<T>(); } 00180 /** 00181 * A synonym for GRS80_a<real>(). 00182 **********************************************************************/ 00183 static inline Math::real GRS80_a() { return GRS80_a<real>(); } 00184 /** 00185 * @tparam T the type of the returned value. 00186 * @return the gravitational constant of the GRS80 ellipsoid, \e GM, in 00187 * m<sup>3</sup> s<sup>−2</sup>. 00188 **********************************************************************/ 00189 template<typename T> static inline T GRS80_GM() 00190 { return T(3986005) * 100000000; } 00191 /** 00192 * A synonym for GRS80_GM<real>(). 00193 **********************************************************************/ 00194 static inline Math::real GRS80_GM() { return GRS80_GM<real>(); } 00195 /** 00196 * @tparam T the type of the returned value. 00197 * @return the angular velocity of the GRS80 ellipsoid, ω, in rad 00198 * s<sup>−1</sup>. 00199 * 00200 * This is about 2 π 366.25 / (365.25 × 24 × 3600) rad 00201 * s<sup>−1</sup>. 365.25 is the number of days in a Julian year and 00202 * 365.35/366.25 converts from solar days to sidereal days. Using the 00203 * number of days in a Gregorian year (365.2425) results in a worse 00204 * approximation (because the Gregorian year includes the precession of the 00205 * earth's axis). 00206 **********************************************************************/ 00207 template<typename T> static inline T GRS80_omega() 00208 { return 7292115 / (T(1000000) * 100000); } 00209 /** 00210 * A synonym for GRS80_omega<real>(). 00211 **********************************************************************/ 00212 static inline Math::real GRS80_omega() { return GRS80_omega<real>(); } 00213 /** 00214 * @tparam T the type of the returned value. 00215 * @return the dynamical form factor of the GRS80 ellipsoid, 00216 * <i>J</i><sub>2</sub>. 00217 **********************************************************************/ 00218 template<typename T> static inline T GRS80_J2() 00219 { return T(108263) / 100000000; } 00220 /** 00221 * A synonym for GRS80_J2<real>(). 00222 **********************************************************************/ 00223 static inline Math::real GRS80_J2() { return GRS80_J2<real>(); } 00224 /** 00225 * @tparam T the type of the returned value. 00226 * @return the central scale factor for UTM (0.9996). 00227 **********************************************************************/ 00228 template<typename T> static inline T UTM_k0() 00229 {return T(9996) / 10000; } 00230 /** 00231 * A synonym for UTM_k0<real>(). 00232 **********************************************************************/ 00233 static inline Math::real UTM_k0() { return UTM_k0<real>(); } 00234 /** 00235 * @tparam T the type of the returned value. 00236 * @return the central scale factor for UPS (0.994). 00237 **********************************************************************/ 00238 template<typename T> static inline T UPS_k0() 00239 { return T(994) / 1000; } 00240 /** 00241 * A synonym for UPS_k0<real>(). 00242 **********************************************************************/ 00243 static inline Math::real UPS_k0() { return UPS_k0<real>(); } 00244 ///@} 00245 00246 /** \name SI units 00247 **********************************************************************/ 00248 ///@{ 00249 /** 00250 * @tparam T the type of the returned value. 00251 * @return the number of meters in a meter. 00252 * 00253 * This is unity, but this lets the internal system of units be changed if 00254 * necessary. 00255 **********************************************************************/ 00256 template<typename T> static inline T meter() { return T(1); } 00257 /** 00258 * A synonym for meter<real>(). 00259 **********************************************************************/ 00260 static inline Math::real meter() { return meter<real>(); } 00261 /** 00262 * @return the number of meters in a kilometer. 00263 **********************************************************************/ 00264 static inline Math::real kilometer() 00265 { return 1000 * meter<real>(); } 00266 /** 00267 * @return the number of meters in a nautical mile (approximately 1 arc 00268 * minute) 00269 **********************************************************************/ 00270 static inline Math::real nauticalmile() 00271 { return 1852 * meter<real>(); } 00272 00273 /** 00274 * @tparam T the type of the returned value. 00275 * @return the number of square meters in a square meter. 00276 * 00277 * This is unity, but this lets the internal system of units be changed if 00278 * necessary. 00279 **********************************************************************/ 00280 template<typename T> static inline T square_meter() 00281 { return meter<real>() * meter<real>(); } 00282 /** 00283 * A synonym for square_meter<real>(). 00284 **********************************************************************/ 00285 static inline Math::real square_meter() 00286 { return square_meter<real>(); } 00287 /** 00288 * @return the number of square meters in a hectare. 00289 **********************************************************************/ 00290 static inline Math::real hectare() 00291 { return 10000 * square_meter<real>(); } 00292 /** 00293 * @return the number of square meters in a square kilometer. 00294 **********************************************************************/ 00295 static inline Math::real square_kilometer() 00296 { return kilometer() * kilometer(); } 00297 /** 00298 * @return the number of square meters in a square nautical mile. 00299 **********************************************************************/ 00300 static inline Math::real square_nauticalmile() 00301 { return nauticalmile() * nauticalmile(); } 00302 ///@} 00303 00304 /** \name Anachronistic British units 00305 **********************************************************************/ 00306 ///@{ 00307 /** 00308 * @return the number of meters in an international foot. 00309 **********************************************************************/ 00310 static inline Math::real foot() 00311 { return real(254 * 12) / 10000 * meter<real>(); } 00312 /** 00313 * @return the number of meters in a yard. 00314 **********************************************************************/ 00315 static inline Math::real yard() { return 3 * foot(); } 00316 /** 00317 * @return the number of meters in a fathom. 00318 **********************************************************************/ 00319 static inline Math::real fathom() { return 2 * yard(); } 00320 /** 00321 * @return the number of meters in a chain. 00322 **********************************************************************/ 00323 static inline Math::real chain() { return 22 * yard(); } 00324 /** 00325 * @return the number of meters in a furlong. 00326 **********************************************************************/ 00327 static inline Math::real furlong() { return 10 * chain(); } 00328 /** 00329 * @return the number of meters in a statute mile. 00330 **********************************************************************/ 00331 static inline Math::real mile() { return 8 * furlong(); } 00332 /** 00333 * @return the number of square meters in an acre. 00334 **********************************************************************/ 00335 static inline Math::real acre() { return chain() * furlong(); } 00336 /** 00337 * @return the number of square meters in a square statute mile. 00338 **********************************************************************/ 00339 static inline Math::real square_mile() { return mile() * mile(); } 00340 ///@} 00341 00342 /** \name Anachronistic US units 00343 **********************************************************************/ 00344 ///@{ 00345 /** 00346 * @return the number of meters in a US survey foot. 00347 **********************************************************************/ 00348 static inline Math::real surveyfoot() 00349 { return real(1200) / 3937 * meter<real>(); } 00350 ///@} 00351 }; 00352 00353 /** 00354 * \brief Exception handling for %GeographicLib 00355 * 00356 * A class to handle exceptions. It's derived from std::runtime_error so it 00357 * can be caught by the usual catch clauses. 00358 * 00359 * Example of use: 00360 * \include example-GeographicErr.cpp 00361 **********************************************************************/ 00362 class GeographicErr : public std::runtime_error { 00363 public: 00364 00365 /** 00366 * Constructor 00367 * 00368 * @param[in] msg a string message, which is accessible in the catch 00369 * clause via what(). 00370 **********************************************************************/ 00371 GeographicErr(const std::string& msg) : std::runtime_error(msg) {} 00372 }; 00373 00374 } // namespace GeographicLib 00375 00376 #endif // GEOGRAPHICLIB_CONSTANTS_HPP