sts.hpp 10 KB

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