airy.hpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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, 2019.
  4. // Modifications copyright (c) 2017-2019, 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. bool no_cut; /* do not cut at hemisphere limit */
  65. };
  66. template <typename T, typename Parameters>
  67. struct base_airy_spheroid
  68. {
  69. par_airy<T> m_proj_parm;
  70. // FORWARD(s_forward) spheroid
  71. // Project coordinates from geographic (lon, lat) to cartesian (x, y)
  72. inline void fwd(Parameters const& , T const& lp_lon, T lp_lat, T& xy_x, T& xy_y) const
  73. {
  74. static const T half_pi = detail::half_pi<T>();
  75. T sinlam, coslam, cosphi, sinphi, t, s, Krho, cosz;
  76. sinlam = sin(lp_lon);
  77. coslam = cos(lp_lon);
  78. switch (this->m_proj_parm.mode) {
  79. case equit:
  80. case obliq:
  81. sinphi = sin(lp_lat);
  82. cosphi = cos(lp_lat);
  83. cosz = cosphi * coslam;
  84. if (this->m_proj_parm.mode == obliq)
  85. cosz = this->m_proj_parm.sinph0 * sinphi + this->m_proj_parm.cosph0 * cosz;
  86. if (!this->m_proj_parm.no_cut && cosz < -epsilon) {
  87. BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
  88. }
  89. if (fabs(s = 1. - cosz) > epsilon) {
  90. t = 0.5 * (1. + cosz);
  91. Krho = -log(t)/s - this->m_proj_parm.Cb / t;
  92. } else
  93. Krho = 0.5 - this->m_proj_parm.Cb;
  94. xy_x = Krho * cosphi * sinlam;
  95. if (this->m_proj_parm.mode == obliq)
  96. xy_y = Krho * (this->m_proj_parm.cosph0 * sinphi -
  97. this->m_proj_parm.sinph0 * cosphi * coslam);
  98. else
  99. xy_y = Krho * sinphi;
  100. break;
  101. case s_pole:
  102. case n_pole:
  103. lp_lat = fabs(this->m_proj_parm.p_halfpi - lp_lat);
  104. if (!this->m_proj_parm.no_cut && (lp_lat - epsilon) > half_pi)
  105. BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
  106. if ((lp_lat *= 0.5) > epsilon) {
  107. t = tan(lp_lat);
  108. Krho = -2.*(log(cos(lp_lat)) / t + t * this->m_proj_parm.Cb);
  109. xy_x = Krho * sinlam;
  110. xy_y = Krho * coslam;
  111. if (this->m_proj_parm.mode == n_pole)
  112. xy_y = -xy_y;
  113. } else
  114. xy_x = xy_y = 0.;
  115. }
  116. }
  117. static inline std::string get_name()
  118. {
  119. return "airy_spheroid";
  120. }
  121. };
  122. // Airy
  123. template <typename Params, typename Parameters, typename T>
  124. inline void setup_airy(Params const& params, Parameters& par, par_airy<T>& proj_parm)
  125. {
  126. static const T half_pi = detail::half_pi<T>();
  127. T beta;
  128. proj_parm.no_cut = pj_get_param_b<srs::spar::no_cut>(params, "no_cut", srs::dpar::no_cut);
  129. beta = 0.5 * (half_pi - pj_get_param_r<T, srs::spar::lat_b>(params, "lat_b", srs::dpar::lat_b));
  130. if (fabs(beta) < epsilon)
  131. proj_parm.Cb = -0.5;
  132. else {
  133. proj_parm.Cb = 1./tan(beta);
  134. proj_parm.Cb *= proj_parm.Cb * log(cos(beta));
  135. }
  136. if (fabs(fabs(par.phi0) - half_pi) < epsilon)
  137. if (par.phi0 < 0.) {
  138. proj_parm.p_halfpi = -half_pi;
  139. proj_parm.mode = s_pole;
  140. } else {
  141. proj_parm.p_halfpi = half_pi;
  142. proj_parm.mode = n_pole;
  143. }
  144. else {
  145. if (fabs(par.phi0) < epsilon)
  146. proj_parm.mode = equit;
  147. else {
  148. proj_parm.mode = obliq;
  149. proj_parm.sinph0 = sin(par.phi0);
  150. proj_parm.cosph0 = cos(par.phi0);
  151. }
  152. }
  153. par.es = 0.;
  154. }
  155. }} // namespace detail::airy
  156. #endif // doxygen
  157. /*!
  158. \brief Airy projection
  159. \ingroup projections
  160. \tparam Geographic latlong point type
  161. \tparam Cartesian xy point type
  162. \tparam Parameters parameter type
  163. \par Projection characteristics
  164. - Miscellaneous
  165. - Spheroid
  166. - no inverse
  167. \par Projection parameters
  168. - no_cut: Do not cut at hemisphere limit (boolean)
  169. - lat_b (degrees)
  170. \par Example
  171. \image html ex_airy.gif
  172. */
  173. template <typename T, typename Parameters>
  174. struct airy_spheroid : public detail::airy::base_airy_spheroid<T, Parameters>
  175. {
  176. template <typename Params>
  177. inline airy_spheroid(Params const& params, Parameters & par)
  178. {
  179. detail::airy::setup_airy(params, par, this->m_proj_parm);
  180. }
  181. };
  182. #ifndef DOXYGEN_NO_DETAIL
  183. namespace detail
  184. {
  185. // Static projection
  186. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(srs::spar::proj_airy, airy_spheroid)
  187. // Factory entry(s)
  188. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(airy_entry, airy_spheroid)
  189. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(airy_init)
  190. {
  191. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(airy, airy_entry)
  192. }
  193. } // namespace detail
  194. #endif // doxygen
  195. } // namespace projections
  196. }} // namespace boost::geometry
  197. #endif // BOOST_GEOMETRY_PROJECTIONS_AIRY_HPP