airy.hpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. // Boost.Geometry - gis-projections (based on PROJ4)
  2. // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2017, 2018.
  4. // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle.
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. // This file is converted from PROJ4, http://trac.osgeo.org/proj
  10. // PROJ4 is originally written by Gerald Evenden (then of the USGS)
  11. // PROJ4 is maintained by Frank Warmerdam
  12. // PROJ4 is converted to Boost.Geometry by Barend Gehrels
  13. // Last updated version of proj: 5.0.0
  14. // Original copyright notice:
  15. // Purpose: Implementation of the airy (Airy) projection.
  16. // Author: Gerald Evenden (1995)
  17. // Thomas Knudsen (2016) - revise/add regression tests
  18. // Copyright (c) 1995, Gerald Evenden
  19. // Permission is hereby granted, free of charge, to any person obtaining a
  20. // copy of this software and associated documentation files (the "Software"),
  21. // to deal in the Software without restriction, including without limitation
  22. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  23. // and/or sell copies of the Software, and to permit persons to whom the
  24. // Software is furnished to do so, subject to the following conditions:
  25. // The above copyright notice and this permission notice shall be included
  26. // in all copies or substantial portions of the Software.
  27. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  28. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  29. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  30. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  31. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  32. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  33. // DEALINGS IN THE SOFTWARE.
  34. #ifndef BOOST_GEOMETRY_PROJECTIONS_AIRY_HPP
  35. #define BOOST_GEOMETRY_PROJECTIONS_AIRY_HPP
  36. #include <boost/geometry/srs/projections/impl/base_static.hpp>
  37. #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
  38. #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
  39. #include <boost/geometry/srs/projections/impl/pj_param.hpp>
  40. #include <boost/geometry/srs/projections/impl/projects.hpp>
  41. #include <boost/geometry/util/math.hpp>
  42. namespace boost { namespace geometry
  43. {
  44. namespace projections
  45. {
  46. #ifndef DOXYGEN_NO_DETAIL
  47. namespace detail { namespace airy
  48. {
  49. static const double epsilon = 1.e-10;
  50. enum mode_type {
  51. n_pole = 0,
  52. s_pole = 1,
  53. equit = 2,
  54. obliq = 3
  55. };
  56. template <typename T>
  57. struct par_airy
  58. {
  59. T p_halfpi;
  60. T sinph0;
  61. T cosph0;
  62. T Cb;
  63. mode_type mode;
  64. int no_cut; /* do not cut at hemisphere limit */
  65. };
  66. // template class, using CRTP to implement forward/inverse
  67. template <typename T, typename Parameters>
  68. struct base_airy_spheroid
  69. : public base_t_f<base_airy_spheroid<T, Parameters>, T, Parameters>
  70. {
  71. par_airy<T> m_proj_parm;
  72. inline base_airy_spheroid(const Parameters& par)
  73. : base_t_f<base_airy_spheroid<T, Parameters>, T, Parameters>(*this, par)
  74. {}
  75. // FORWARD(s_forward) spheroid
  76. // Project coordinates from geographic (lon, lat) to cartesian (x, y)
  77. inline void fwd(T const& lp_lon, T lp_lat, T& xy_x, T& xy_y) const
  78. {
  79. static const T half_pi = detail::half_pi<T>();
  80. T sinlam, coslam, cosphi, sinphi, t, s, Krho, cosz;
  81. sinlam = sin(lp_lon);
  82. coslam = cos(lp_lon);
  83. switch (this->m_proj_parm.mode) {
  84. case equit:
  85. case obliq:
  86. sinphi = sin(lp_lat);
  87. cosphi = cos(lp_lat);
  88. cosz = cosphi * coslam;
  89. if (this->m_proj_parm.mode == obliq)
  90. cosz = this->m_proj_parm.sinph0 * sinphi + this->m_proj_parm.cosph0 * cosz;
  91. if (!this->m_proj_parm.no_cut && cosz < -epsilon) {
  92. BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
  93. }
  94. if (fabs(s = 1. - cosz) > epsilon) {
  95. t = 0.5 * (1. + cosz);
  96. Krho = -log(t)/s - this->m_proj_parm.Cb / t;
  97. } else
  98. Krho = 0.5 - this->m_proj_parm.Cb;
  99. xy_x = Krho * cosphi * sinlam;
  100. if (this->m_proj_parm.mode == obliq)
  101. xy_y = Krho * (this->m_proj_parm.cosph0 * sinphi -
  102. this->m_proj_parm.sinph0 * cosphi * coslam);
  103. else
  104. xy_y = Krho * sinphi;
  105. break;
  106. case s_pole:
  107. case n_pole:
  108. lp_lat = fabs(this->m_proj_parm.p_halfpi - lp_lat);
  109. if (!this->m_proj_parm.no_cut && (lp_lat - epsilon) > half_pi)
  110. BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
  111. if ((lp_lat *= 0.5) > epsilon) {
  112. t = tan(lp_lat);
  113. Krho = -2.*(log(cos(lp_lat)) / t + t * this->m_proj_parm.Cb);
  114. xy_x = Krho * sinlam;
  115. xy_y = Krho * coslam;
  116. if (this->m_proj_parm.mode == n_pole)
  117. xy_y = -xy_y;
  118. } else
  119. xy_x = xy_y = 0.;
  120. }
  121. }
  122. static inline std::string get_name()
  123. {
  124. return "airy_spheroid";
  125. }
  126. };
  127. // Airy
  128. template <typename Params, typename Parameters, typename T>
  129. inline void setup_airy(Params const& params, Parameters& par, par_airy<T>& proj_parm)
  130. {
  131. static const T half_pi = detail::half_pi<T>();
  132. T beta;
  133. proj_parm.no_cut = pj_get_param_b<srs::spar::no_cut>(params, "no_cut", srs::dpar::no_cut);
  134. beta = 0.5 * (half_pi - pj_get_param_r<T, srs::spar::lat_b>(params, "lat_b", srs::dpar::lat_b));
  135. if (fabs(beta) < epsilon)
  136. proj_parm.Cb = -0.5;
  137. else {
  138. proj_parm.Cb = 1./tan(beta);
  139. proj_parm.Cb *= proj_parm.Cb * log(cos(beta));
  140. }
  141. if (fabs(fabs(par.phi0) - half_pi) < epsilon)
  142. if (par.phi0 < 0.) {
  143. proj_parm.p_halfpi = -half_pi;
  144. proj_parm.mode = s_pole;
  145. } else {
  146. proj_parm.p_halfpi = half_pi;
  147. proj_parm.mode = n_pole;
  148. }
  149. else {
  150. if (fabs(par.phi0) < epsilon)
  151. proj_parm.mode = equit;
  152. else {
  153. proj_parm.mode = obliq;
  154. proj_parm.sinph0 = sin(par.phi0);
  155. proj_parm.cosph0 = cos(par.phi0);
  156. }
  157. }
  158. par.es = 0.;
  159. }
  160. }} // namespace detail::airy
  161. #endif // doxygen
  162. /*!
  163. \brief Airy projection
  164. \ingroup projections
  165. \tparam Geographic latlong point type
  166. \tparam Cartesian xy point type
  167. \tparam Parameters parameter type
  168. \par Projection characteristics
  169. - Miscellaneous
  170. - Spheroid
  171. - no inverse
  172. \par Projection parameters
  173. - no_cut: Do not cut at hemisphere limit (boolean)
  174. - lat_b (degrees)
  175. \par Example
  176. \image html ex_airy.gif
  177. */
  178. template <typename T, typename Parameters>
  179. struct airy_spheroid : public detail::airy::base_airy_spheroid<T, Parameters>
  180. {
  181. template <typename Params>
  182. inline airy_spheroid(Params const& params, Parameters const& par)
  183. : detail::airy::base_airy_spheroid<T, Parameters>(par)
  184. {
  185. detail::airy::setup_airy(params, this->m_par, this->m_proj_parm);
  186. }
  187. };
  188. #ifndef DOXYGEN_NO_DETAIL
  189. namespace detail
  190. {
  191. // Static projection
  192. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::spar::proj_airy, airy_spheroid, airy_spheroid)
  193. // Factory entry(s)
  194. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(airy_entry, airy_spheroid)
  195. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(airy_init)
  196. {
  197. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(airy, airy_entry)
  198. }
  199. } // namespace detail
  200. #endif // doxygen
  201. } // namespace projections
  202. }} // namespace boost::geometry
  203. #endif // BOOST_GEOMETRY_PROJECTIONS_AIRY_HPP