sts.hpp 12 KB

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