sts.hpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. // 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_STS_HPP
  31. #define BOOST_GEOMETRY_PROJECTIONS_STS_HPP
  32. #include <boost/geometry/srs/projections/impl/base_static.hpp>
  33. #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
  34. #include <boost/geometry/srs/projections/impl/projects.hpp>
  35. #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
  36. #include <boost/geometry/srs/projections/impl/aasincos.hpp>
  37. namespace boost { namespace geometry
  38. {
  39. namespace projections
  40. {
  41. #ifndef DOXYGEN_NO_DETAIL
  42. namespace detail { namespace sts
  43. {
  44. template <typename T>
  45. struct par_sts
  46. {
  47. T C_x, C_y, C_p;
  48. bool tan_mode;
  49. };
  50. template <typename T, typename Parameters>
  51. struct base_sts_spheroid
  52. {
  53. par_sts<T> m_proj_parm;
  54. // FORWARD(s_forward) spheroid
  55. // Project coordinates from geographic (lon, lat) to cartesian (x, y)
  56. inline void fwd(Parameters const& , T const& lp_lon, T lp_lat, T& xy_x, T& xy_y) const
  57. {
  58. T c;
  59. xy_x = this->m_proj_parm.C_x * lp_lon * cos(lp_lat);
  60. xy_y = this->m_proj_parm.C_y;
  61. lp_lat *= this->m_proj_parm.C_p;
  62. c = cos(lp_lat);
  63. if (this->m_proj_parm.tan_mode) {
  64. xy_x *= c * c;
  65. xy_y *= tan(lp_lat);
  66. } else {
  67. xy_x /= c;
  68. xy_y *= sin(lp_lat);
  69. }
  70. }
  71. // INVERSE(s_inverse) spheroid
  72. // Project coordinates from cartesian (x, y) to geographic (lon, lat)
  73. inline void inv(Parameters const& , T const& xy_x, T xy_y, T& lp_lon, T& lp_lat) const
  74. {
  75. T c;
  76. xy_y /= this->m_proj_parm.C_y;
  77. c = cos(lp_lat = this->m_proj_parm.tan_mode ? atan(xy_y) : aasin(xy_y));
  78. lp_lat /= this->m_proj_parm.C_p;
  79. lp_lon = xy_x / (this->m_proj_parm.C_x * cos(lp_lat));
  80. if (this->m_proj_parm.tan_mode)
  81. lp_lon /= c * c;
  82. else
  83. lp_lon *= c;
  84. }
  85. static inline std::string get_name()
  86. {
  87. return "sts_spheroid";
  88. }
  89. };
  90. template <typename Parameters, typename T>
  91. inline void setup(Parameters& par, par_sts<T>& proj_parm, T const& p, T const& q, bool mode)
  92. {
  93. par.es = 0.;
  94. proj_parm.C_x = q / p;
  95. proj_parm.C_y = p;
  96. proj_parm.C_p = 1/ q;
  97. proj_parm.tan_mode = mode;
  98. }
  99. // Foucaut
  100. template <typename Parameters, typename T>
  101. inline void setup_fouc(Parameters& par, par_sts<T>& proj_parm)
  102. {
  103. setup(par, proj_parm, 2., 2., true);
  104. }
  105. // Kavraisky V
  106. template <typename Parameters, typename T>
  107. inline void setup_kav5(Parameters& par, par_sts<T>& proj_parm)
  108. {
  109. setup(par, proj_parm, 1.50488, 1.35439, false);
  110. }
  111. // Quartic Authalic
  112. template <typename Parameters, typename T>
  113. inline void setup_qua_aut(Parameters& par, par_sts<T>& proj_parm)
  114. {
  115. setup(par, proj_parm, 2., 2., false);
  116. }
  117. // McBryde-Thomas Flat-Polar Sine (No. 1)
  118. template <typename Parameters, typename T>
  119. inline void setup_mbt_s(Parameters& par, par_sts<T>& proj_parm)
  120. {
  121. setup(par, proj_parm, 1.48875, 1.36509, false);
  122. }
  123. }} // namespace detail::sts
  124. #endif // doxygen
  125. /*!
  126. \brief Kavraisky V projection
  127. \ingroup projections
  128. \tparam Geographic latlong point type
  129. \tparam Cartesian xy point type
  130. \tparam Parameters parameter type
  131. \par Projection characteristics
  132. - Pseudocylindrical
  133. - Spheroid
  134. \par Example
  135. \image html ex_kav5.gif
  136. */
  137. template <typename T, typename Parameters>
  138. struct kav5_spheroid : public detail::sts::base_sts_spheroid<T, Parameters>
  139. {
  140. template <typename Params>
  141. inline kav5_spheroid(Params const& , Parameters & par)
  142. {
  143. detail::sts::setup_kav5(par, this->m_proj_parm);
  144. }
  145. };
  146. /*!
  147. \brief Quartic Authalic projection
  148. \ingroup projections
  149. \tparam Geographic latlong point type
  150. \tparam Cartesian xy point type
  151. \tparam Parameters parameter type
  152. \par Projection characteristics
  153. - Pseudocylindrical
  154. - Spheroid
  155. \par Example
  156. \image html ex_qua_aut.gif
  157. */
  158. template <typename T, typename Parameters>
  159. struct qua_aut_spheroid : public detail::sts::base_sts_spheroid<T, Parameters>
  160. {
  161. template <typename Params>
  162. inline qua_aut_spheroid(Params const& , Parameters & par)
  163. {
  164. detail::sts::setup_qua_aut(par, this->m_proj_parm);
  165. }
  166. };
  167. /*!
  168. \brief McBryde-Thomas Flat-Polar Sine (No. 1) projection
  169. \ingroup projections
  170. \tparam Geographic latlong point type
  171. \tparam Cartesian xy point type
  172. \tparam Parameters parameter type
  173. \par Projection characteristics
  174. - Pseudocylindrical
  175. - Spheroid
  176. \par Example
  177. \image html ex_mbt_s.gif
  178. */
  179. template <typename T, typename Parameters>
  180. struct mbt_s_spheroid : public detail::sts::base_sts_spheroid<T, Parameters>
  181. {
  182. template <typename Params>
  183. inline mbt_s_spheroid(Params const& , Parameters & par)
  184. {
  185. detail::sts::setup_mbt_s(par, this->m_proj_parm);
  186. }
  187. };
  188. /*!
  189. \brief Foucaut projection
  190. \ingroup projections
  191. \tparam Geographic latlong point type
  192. \tparam Cartesian xy point type
  193. \tparam Parameters parameter type
  194. \par Projection characteristics
  195. - Pseudocylindrical
  196. - Spheroid
  197. \par Example
  198. \image html ex_fouc.gif
  199. */
  200. template <typename T, typename Parameters>
  201. struct fouc_spheroid : public detail::sts::base_sts_spheroid<T, Parameters>
  202. {
  203. template <typename Params>
  204. inline fouc_spheroid(Params const& , Parameters & par)
  205. {
  206. detail::sts::setup_fouc(par, this->m_proj_parm);
  207. }
  208. };
  209. #ifndef DOXYGEN_NO_DETAIL
  210. namespace detail
  211. {
  212. // Static projection
  213. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_kav5, kav5_spheroid)
  214. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_qua_aut, qua_aut_spheroid)
  215. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_mbt_s, mbt_s_spheroid)
  216. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_fouc, fouc_spheroid)
  217. // Factory entry(s)
  218. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(kav5_entry, kav5_spheroid)
  219. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(qua_aut_entry, qua_aut_spheroid)
  220. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(mbt_s_entry, mbt_s_spheroid)
  221. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(fouc_entry, fouc_spheroid)
  222. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(sts_init)
  223. {
  224. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(kav5, kav5_entry)
  225. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(qua_aut, qua_aut_entry)
  226. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(mbt_s, mbt_s_entry)
  227. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(fouc, fouc_entry)
  228. }
  229. } // namespace detail
  230. #endif // doxygen
  231. } // namespace projections
  232. }} // namespace boost::geometry
  233. #endif // BOOST_GEOMETRY_PROJECTIONS_STS_HPP