ocea.hpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. // Permission is hereby granted, free of charge, to any person obtaining a
  16. // copy of this software and associated documentation files (the "Software"),
  17. // to deal in the Software without restriction, including without limitation
  18. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  19. // and/or sell copies of the Software, and to permit persons to whom the
  20. // Software is furnished to do so, subject to the following conditions:
  21. // The above copyright notice and this permission notice shall be included
  22. // in all copies or substantial portions of the Software.
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  24. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  26. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  28. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  29. // DEALINGS IN THE SOFTWARE.
  30. #ifndef BOOST_GEOMETRY_PROJECTIONS_OCEA_HPP
  31. #define BOOST_GEOMETRY_PROJECTIONS_OCEA_HPP
  32. #include <boost/geometry/util/math.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/factory_entry.hpp>
  36. #include <boost/geometry/srs/projections/impl/pj_param.hpp>
  37. #include <boost/geometry/srs/projections/impl/projects.hpp>
  38. namespace boost { namespace geometry
  39. {
  40. namespace projections
  41. {
  42. #ifndef DOXYGEN_NO_DETAIL
  43. namespace detail { namespace ocea
  44. {
  45. template <typename T>
  46. struct par_ocea
  47. {
  48. T rok;
  49. T rtk;
  50. T sinphi;
  51. T cosphi;
  52. T singam;
  53. T cosgam;
  54. };
  55. // template class, using CRTP to implement forward/inverse
  56. template <typename T, typename Parameters>
  57. struct base_ocea_spheroid
  58. : public base_t_fi<base_ocea_spheroid<T, Parameters>, T, Parameters>
  59. {
  60. par_ocea<T> m_proj_parm;
  61. inline base_ocea_spheroid(const Parameters& par)
  62. : base_t_fi<base_ocea_spheroid<T, Parameters>,
  63. T, Parameters>(*this, par) {}
  64. // FORWARD(s_forward) spheroid
  65. // Project coordinates from geographic (lon, lat) to cartesian (x, y)
  66. inline void fwd(T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
  67. {
  68. static const T pi = detail::pi<T>();
  69. T t;
  70. xy_y = sin(lp_lon);
  71. t = cos(lp_lon);
  72. xy_x = atan((tan(lp_lat) * this->m_proj_parm.cosphi + this->m_proj_parm.sinphi * xy_y) / t);
  73. if (t < 0.)
  74. xy_x += pi;
  75. xy_x *= this->m_proj_parm.rtk;
  76. xy_y = this->m_proj_parm.rok * (this->m_proj_parm.sinphi * sin(lp_lat) - this->m_proj_parm.cosphi * cos(lp_lat) * xy_y);
  77. }
  78. // INVERSE(s_inverse) spheroid
  79. // Project coordinates from cartesian (x, y) to geographic (lon, lat)
  80. inline void inv(T xy_x, T xy_y, T& lp_lon, T& lp_lat) const
  81. {
  82. T t, s;
  83. xy_y /= this->m_proj_parm.rok;
  84. xy_x /= this->m_proj_parm.rtk;
  85. t = sqrt(1. - xy_y * xy_y);
  86. lp_lat = asin(xy_y * this->m_proj_parm.sinphi + t * this->m_proj_parm.cosphi * (s = sin(xy_x)));
  87. lp_lon = atan2(t * this->m_proj_parm.sinphi * s - xy_y * this->m_proj_parm.cosphi,
  88. t * cos(xy_x));
  89. }
  90. static inline std::string get_name()
  91. {
  92. return "ocea_spheroid";
  93. }
  94. };
  95. // Oblique Cylindrical Equal Area
  96. template <typename Params, typename Parameters, typename T>
  97. inline void setup_ocea(Params const& params, Parameters& par, par_ocea<T>& proj_parm)
  98. {
  99. static const T half_pi = detail::half_pi<T>();
  100. T phi_0=0.0, phi_1, phi_2, lam_1, lam_2, lonz, alpha;
  101. proj_parm.rok = 1. / par.k0;
  102. proj_parm.rtk = par.k0;
  103. /*If the keyword "alpha" is found in the sentence then use 1point+1azimuth*/
  104. if ( pj_param_r<srs::spar::alpha>(params, "alpha", srs::dpar::alpha, alpha)) {
  105. /*Define Pole of oblique transformation from 1 point & 1 azimuth*/
  106. //alpha = pj_get_param_r(par.params, "alpha"); // set above
  107. lonz = pj_get_param_r<T, srs::spar::lonc>(params, "lonc", srs::dpar::lonc);
  108. /*Equation 9-8 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
  109. proj_parm.singam = atan(-cos(alpha)/(-sin(phi_0) * sin(alpha))) + lonz;
  110. /*Equation 9-7 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
  111. proj_parm.sinphi = asin(cos(phi_0) * sin(alpha));
  112. /*If the keyword "alpha" is NOT found in the sentence then use 2points*/
  113. } else {
  114. /*Define Pole of oblique transformation from 2 points*/
  115. phi_1 = pj_get_param_r<T, srs::spar::lat_1>(params, "lat_1", srs::dpar::lat_1);
  116. phi_2 = pj_get_param_r<T, srs::spar::lat_2>(params, "lat_2", srs::dpar::lat_2);
  117. lam_1 = pj_get_param_r<T, srs::spar::lon_1>(params, "lon_1", srs::dpar::lon_1);
  118. lam_2 = pj_get_param_r<T, srs::spar::lon_2>(params, "lon_2", srs::dpar::lon_2);
  119. /*Equation 9-1 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
  120. proj_parm.singam = atan2(cos(phi_1) * sin(phi_2) * cos(lam_1) -
  121. sin(phi_1) * cos(phi_2) * cos(lam_2),
  122. sin(phi_1) * cos(phi_2) * sin(lam_2) -
  123. cos(phi_1) * sin(phi_2) * sin(lam_1) );
  124. /* take care of P->lam0 wrap-around when +lam_1=-90*/
  125. if (lam_1 == -half_pi)
  126. proj_parm.singam = -proj_parm.singam;
  127. /*Equation 9-2 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
  128. proj_parm.sinphi = atan(-cos(proj_parm.singam - lam_1) / tan(phi_1));
  129. }
  130. par.lam0 = proj_parm.singam + half_pi;
  131. proj_parm.cosphi = cos(proj_parm.sinphi);
  132. proj_parm.sinphi = sin(proj_parm.sinphi);
  133. proj_parm.cosgam = cos(proj_parm.singam);
  134. proj_parm.singam = sin(proj_parm.singam);
  135. par.es = 0.;
  136. }
  137. }} // namespace detail::ocea
  138. #endif // doxygen
  139. /*!
  140. \brief Oblique Cylindrical Equal Area projection
  141. \ingroup projections
  142. \tparam Geographic latlong point type
  143. \tparam Cartesian xy point type
  144. \tparam Parameters parameter type
  145. \par Projection characteristics
  146. - Cylindrical
  147. - Spheroid
  148. \par Projection parameters
  149. - lonc: Longitude (only used if alpha (or gamma) is specified) (degrees)
  150. - alpha: Alpha (degrees)
  151. - lat_1: Latitude of first standard parallel (degrees)
  152. - lat_2: Latitude of second standard parallel (degrees)
  153. - lon_1 (degrees)
  154. - lon_2 (degrees)
  155. \par Example
  156. \image html ex_ocea.gif
  157. */
  158. template <typename T, typename Parameters>
  159. struct ocea_spheroid : public detail::ocea::base_ocea_spheroid<T, Parameters>
  160. {
  161. template <typename Params>
  162. inline ocea_spheroid(Params const& params, Parameters const& par)
  163. : detail::ocea::base_ocea_spheroid<T, Parameters>(par)
  164. {
  165. detail::ocea::setup_ocea(params, this->m_par, this->m_proj_parm);
  166. }
  167. };
  168. #ifndef DOXYGEN_NO_DETAIL
  169. namespace detail
  170. {
  171. // Static projection
  172. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::spar::proj_ocea, ocea_spheroid, ocea_spheroid)
  173. // Factory entry(s)
  174. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(ocea_entry, ocea_spheroid)
  175. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(ocea_init)
  176. {
  177. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(ocea, ocea_entry)
  178. }
  179. } // namespace detail
  180. #endif // doxygen
  181. } // namespace projections
  182. }} // namespace boost::geometry
  183. #endif // BOOST_GEOMETRY_PROJECTIONS_OCEA_HPP