rouss.hpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. // Copyright (c) 2003, 2006 Gerald I. Evenden
  16. // Permission is hereby granted, free of charge, to any person obtaining a
  17. // copy of this software and associated documentation files (the "Software"),
  18. // to deal in the Software without restriction, including without limitation
  19. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  20. // and/or sell copies of the Software, and to permit persons to whom the
  21. // Software is furnished to do so, subject to the following conditions:
  22. // The above copyright notice and this permission notice shall be included
  23. // in all copies or substantial portions of the Software.
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  25. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  27. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  29. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  30. // DEALINGS IN THE SOFTWARE.
  31. #ifndef BOOST_GEOMETRY_PROJECTIONS_ROUSS_HPP
  32. #define BOOST_GEOMETRY_PROJECTIONS_ROUSS_HPP
  33. #include <boost/geometry/srs/projections/impl/base_static.hpp>
  34. #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
  35. #include <boost/geometry/srs/projections/impl/projects.hpp>
  36. #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
  37. #include <boost/geometry/srs/projections/impl/proj_mdist.hpp>
  38. namespace boost { namespace geometry
  39. {
  40. namespace srs { namespace par4
  41. {
  42. struct rouss {}; // Roussilhe Stereographic
  43. }} //namespace srs::par4
  44. namespace projections
  45. {
  46. #ifndef DOXYGEN_NO_DETAIL
  47. namespace detail { namespace rouss
  48. {
  49. template <typename T>
  50. struct par_rouss
  51. {
  52. T s0;
  53. T A1, A2, A3, A4, A5, A6;
  54. T B1, B2, B3, B4, B5, B6, B7, B8;
  55. T C1, C2, C3, C4, C5, C6, C7, C8;
  56. T D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11;
  57. mdist<T> en;
  58. };
  59. // template class, using CRTP to implement forward/inverse
  60. template <typename T, typename Parameters>
  61. struct base_rouss_ellipsoid
  62. : public base_t_fi<base_rouss_ellipsoid<T, Parameters>, T, Parameters>
  63. {
  64. par_rouss<T> m_proj_parm;
  65. inline base_rouss_ellipsoid(const Parameters& par)
  66. : base_t_fi<base_rouss_ellipsoid<T, Parameters>, T, Parameters>(*this, par)
  67. {}
  68. // FORWARD(e_forward) ellipsoid
  69. // Project coordinates from geographic (lon, lat) to cartesian (x, y)
  70. inline void fwd(T& lp_lon, T& lp_lat, T& xy_x, T& xy_y) const
  71. {
  72. T s, al, cp, sp, al2, s2;
  73. cp = cos(lp_lat);
  74. sp = sin(lp_lat);
  75. s = proj_mdist(lp_lat, sp, cp, this->m_proj_parm.en) - this->m_proj_parm.s0;
  76. s2 = s * s;
  77. al = lp_lon * cp / sqrt(1. - this->m_par.es * sp * sp);
  78. al2 = al * al;
  79. xy_x = this->m_par.k0 * al*(1.+s2*(this->m_proj_parm.A1+s2*this->m_proj_parm.A4)-al2*(this->m_proj_parm.A2+s*this->m_proj_parm.A3+s2*this->m_proj_parm.A5
  80. +al2*this->m_proj_parm.A6));
  81. xy_y = this->m_par.k0 * (al2*(this->m_proj_parm.B1+al2*this->m_proj_parm.B4)+
  82. s*(1.+al2*(this->m_proj_parm.B3-al2*this->m_proj_parm.B6)+s2*(this->m_proj_parm.B2+s2*this->m_proj_parm.B8)+
  83. s*al2*(this->m_proj_parm.B5+s*this->m_proj_parm.B7)));
  84. }
  85. // INVERSE(e_inverse) ellipsoid
  86. // Project coordinates from cartesian (x, y) to geographic (lon, lat)
  87. inline void inv(T& xy_x, T& xy_y, T& lp_lon, T& lp_lat) const
  88. {
  89. T s, al, x = xy_x / this->m_par.k0, y = xy_y / this->m_par.k0, x2, y2;
  90. x2 = x * x;
  91. y2 = y * y;
  92. al = x*(1.-this->m_proj_parm.C1*y2+x2*(this->m_proj_parm.C2+this->m_proj_parm.C3*y-this->m_proj_parm.C4*x2+this->m_proj_parm.C5*y2-this->m_proj_parm.C7*x2*y)
  93. +y2*(this->m_proj_parm.C6*y2-this->m_proj_parm.C8*x2*y));
  94. s = this->m_proj_parm.s0 + y*(1.+y2*(-this->m_proj_parm.D2+this->m_proj_parm.D8*y2))+
  95. x2*(-this->m_proj_parm.D1+y*(-this->m_proj_parm.D3+y*(-this->m_proj_parm.D5+y*(-this->m_proj_parm.D7+y*this->m_proj_parm.D11)))+
  96. x2*(this->m_proj_parm.D4+y*(this->m_proj_parm.D6+y*this->m_proj_parm.D10)-x2*this->m_proj_parm.D9));
  97. lp_lat=proj_inv_mdist(s, this->m_proj_parm.en);
  98. s = sin(lp_lat);
  99. lp_lon=al * sqrt(1. - this->m_par.es * s * s)/cos(lp_lat);
  100. }
  101. static inline std::string get_name()
  102. {
  103. return "rouss_ellipsoid";
  104. }
  105. };
  106. // Roussilhe Stereographic
  107. template <typename Parameters, typename T>
  108. inline void setup_rouss(Parameters& par, par_rouss<T>& proj_parm)
  109. {
  110. T N0, es2, t, t2, R_R0_2, R_R0_4;
  111. if (!proj_mdist_ini(par.es, proj_parm.en))
  112. BOOST_THROW_EXCEPTION( projection_exception(0) );
  113. es2 = sin(par.phi0);
  114. proj_parm.s0 = proj_mdist(par.phi0, es2, cos(par.phi0), proj_parm.en);
  115. t = 1. - (es2 = par.es * es2 * es2);
  116. N0 = 1./sqrt(t);
  117. R_R0_2 = t * t / par.one_es;
  118. R_R0_4 = R_R0_2 * R_R0_2;
  119. t = tan(par.phi0);
  120. t2 = t * t;
  121. proj_parm.C1 = proj_parm.A1 = R_R0_2 / 4.;
  122. proj_parm.C2 = proj_parm.A2 = R_R0_2 * (2 * t2 - 1. - 2. * es2) / 12.;
  123. proj_parm.A3 = R_R0_2 * t * (1. + 4. * t2)/ ( 12. * N0);
  124. proj_parm.A4 = R_R0_4 / 24.;
  125. proj_parm.A5 = R_R0_4 * ( -1. + t2 * (11. + 12. * t2))/24.;
  126. proj_parm.A6 = R_R0_4 * ( -2. + t2 * (11. - 2. * t2))/240.;
  127. proj_parm.B1 = t / (2. * N0);
  128. proj_parm.B2 = R_R0_2 / 12.;
  129. proj_parm.B3 = R_R0_2 * (1. + 2. * t2 - 2. * es2)/4.;
  130. proj_parm.B4 = R_R0_2 * t * (2. - t2)/(24. * N0);
  131. proj_parm.B5 = R_R0_2 * t * (5. + 4.* t2)/(8. * N0);
  132. proj_parm.B6 = R_R0_4 * (-2. + t2 * (-5. + 6. * t2))/48.;
  133. proj_parm.B7 = R_R0_4 * (5. + t2 * (19. + 12. * t2))/24.;
  134. proj_parm.B8 = R_R0_4 / 120.;
  135. proj_parm.C3 = R_R0_2 * t * (1. + t2)/(3. * N0);
  136. proj_parm.C4 = R_R0_4 * (-3. + t2 * (34. + 22. * t2))/240.;
  137. proj_parm.C5 = R_R0_4 * (4. + t2 * (13. + 12. * t2))/24.;
  138. proj_parm.C6 = R_R0_4 / 16.;
  139. proj_parm.C7 = R_R0_4 * t * (11. + t2 * (33. + t2 * 16.))/(48. * N0);
  140. proj_parm.C8 = R_R0_4 * t * (1. + t2 * 4.)/(36. * N0);
  141. proj_parm.D1 = t / (2. * N0);
  142. proj_parm.D2 = R_R0_2 / 12.;
  143. proj_parm.D3 = R_R0_2 * (2 * t2 + 1. - 2. * es2) / 4.;
  144. proj_parm.D4 = R_R0_2 * t * (1. + t2)/(8. * N0);
  145. proj_parm.D5 = R_R0_2 * t * (1. + t2 * 2.)/(4. * N0);
  146. proj_parm.D6 = R_R0_4 * (1. + t2 * (6. + t2 * 6.))/16.;
  147. proj_parm.D7 = R_R0_4 * t2 * (3. + t2 * 4.)/8.;
  148. proj_parm.D8 = R_R0_4 / 80.;
  149. proj_parm.D9 = R_R0_4 * t * (-21. + t2 * (178. - t2 * 26.))/720.;
  150. proj_parm.D10 = R_R0_4 * t * (29. + t2 * (86. + t2 * 48.))/(96. * N0);
  151. proj_parm.D11 = R_R0_4 * t * (37. + t2 * 44.)/(96. * N0);
  152. }
  153. }} // namespace detail::rouss
  154. #endif // doxygen
  155. /*!
  156. \brief Roussilhe Stereographic projection
  157. \ingroup projections
  158. \tparam Geographic latlong point type
  159. \tparam Cartesian xy point type
  160. \tparam Parameters parameter type
  161. \par Projection characteristics
  162. - Azimuthal
  163. - Ellipsoid
  164. \par Example
  165. \image html ex_rouss.gif
  166. */
  167. template <typename T, typename Parameters>
  168. struct rouss_ellipsoid : public detail::rouss::base_rouss_ellipsoid<T, Parameters>
  169. {
  170. inline rouss_ellipsoid(const Parameters& par) : detail::rouss::base_rouss_ellipsoid<T, Parameters>(par)
  171. {
  172. detail::rouss::setup_rouss(this->m_par, this->m_proj_parm);
  173. }
  174. };
  175. #ifndef DOXYGEN_NO_DETAIL
  176. namespace detail
  177. {
  178. // Static projection
  179. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::rouss, rouss_ellipsoid, rouss_ellipsoid)
  180. // Factory entry(s)
  181. template <typename T, typename Parameters>
  182. class rouss_entry : public detail::factory_entry<T, Parameters>
  183. {
  184. public :
  185. virtual base_v<T, Parameters>* create_new(const Parameters& par) const
  186. {
  187. return new base_v_fi<rouss_ellipsoid<T, Parameters>, T, Parameters>(par);
  188. }
  189. };
  190. template <typename T, typename Parameters>
  191. inline void rouss_init(detail::base_factory<T, Parameters>& factory)
  192. {
  193. factory.add_to_factory("rouss", new rouss_entry<T, Parameters>);
  194. }
  195. } // namespace detail
  196. #endif // doxygen
  197. } // namespace projections
  198. }} // namespace boost::geometry
  199. #endif // BOOST_GEOMETRY_PROJECTIONS_ROUSS_HPP