eck3.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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_ECK3_HPP
  31. #define BOOST_GEOMETRY_PROJECTIONS_ECK3_HPP
  32. #include <boost/core/ignore_unused.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/aasincos.hpp>
  38. namespace boost { namespace geometry
  39. {
  40. namespace srs { namespace par4
  41. {
  42. struct eck3 {}; // Eckert III
  43. struct putp1 {}; // Putnins P1
  44. struct wag6 {}; // Wagner VI
  45. struct kav7 {}; // Kavraisky VII
  46. }} //namespace srs::par4
  47. namespace projections
  48. {
  49. #ifndef DOXYGEN_NO_DETAIL
  50. namespace detail { namespace eck3
  51. {
  52. template <typename T>
  53. struct par_eck3
  54. {
  55. T C_x, C_y, A, B;
  56. };
  57. // template class, using CRTP to implement forward/inverse
  58. template <typename T, typename Parameters>
  59. struct base_eck3_spheroid
  60. : public base_t_fi<base_eck3_spheroid<T, Parameters>, T, Parameters>
  61. {
  62. par_eck3<T> m_proj_parm;
  63. inline base_eck3_spheroid(const Parameters& par)
  64. : base_t_fi<base_eck3_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. xy_y = this->m_proj_parm.C_y * lp_lat;
  71. xy_x = this->m_proj_parm.C_x * lp_lon * (this->m_proj_parm.A + asqrt(1. - this->m_proj_parm.B * lp_lat * lp_lat));
  72. }
  73. // INVERSE(s_inverse) spheroid
  74. // Project coordinates from cartesian (x, y) to geographic (lon, lat)
  75. inline void inv(T& xy_x, T& xy_y, T& lp_lon, T& lp_lat) const
  76. {
  77. T denominator;
  78. lp_lat = xy_y / this->m_proj_parm.C_y;
  79. denominator = (this->m_proj_parm.C_x * (this->m_proj_parm.A + asqrt(1. - this->m_proj_parm.B * lp_lat * lp_lat)));
  80. if ( denominator == 0.0) {
  81. lp_lon = HUGE_VAL;
  82. lp_lat = HUGE_VAL;
  83. } else
  84. lp_lon = xy_x / denominator;
  85. }
  86. static inline std::string get_name()
  87. {
  88. return "eck3_spheroid";
  89. }
  90. };
  91. template <typename Parameters>
  92. inline void setup(Parameters& par)
  93. {
  94. par.es = 0.;
  95. }
  96. // Eckert III
  97. template <typename Parameters, typename T>
  98. inline void setup_eck3(Parameters& par, par_eck3<T>& proj_parm)
  99. {
  100. proj_parm.C_x = 0.42223820031577120149;
  101. proj_parm.C_y = 0.84447640063154240298;
  102. proj_parm.A = 1.0;
  103. proj_parm.B = 0.4052847345693510857755;
  104. setup(par);
  105. }
  106. // Putnins P1
  107. template <typename Parameters, typename T>
  108. inline void setup_putp1(Parameters& par, par_eck3<T>& proj_parm)
  109. {
  110. proj_parm.C_x = 1.89490;
  111. proj_parm.C_y = 0.94745;
  112. proj_parm.A = -0.5;
  113. proj_parm.B = 0.30396355092701331433;
  114. setup(par);
  115. }
  116. // Wagner VI
  117. template <typename Parameters, typename T>
  118. inline void setup_wag6(Parameters& par, par_eck3<T>& proj_parm)
  119. {
  120. proj_parm.C_x = proj_parm.C_y = 0.94745;
  121. proj_parm.A = 0.0;
  122. proj_parm.B = 0.30396355092701331433;
  123. setup(par);
  124. }
  125. // Kavraisky VII
  126. template <typename Parameters, typename T>
  127. inline void setup_kav7(Parameters& par, par_eck3<T>& proj_parm)
  128. {
  129. /* Defined twice in original code - Using 0.866...,
  130. * but leaving the other one here as a safety measure.
  131. * proj_parm.C_x = 0.2632401569273184856851; */
  132. proj_parm.C_x = 0.8660254037844;
  133. proj_parm.C_y = 1.0;
  134. proj_parm.A = 0.0;
  135. proj_parm.B = 0.30396355092701331433;
  136. setup(par);
  137. }
  138. }} // namespace detail::eck3
  139. #endif // doxygen
  140. /*!
  141. \brief Eckert III projection
  142. \ingroup projections
  143. \tparam Geographic latlong point type
  144. \tparam Cartesian xy point type
  145. \tparam Parameters parameter type
  146. \par Projection characteristics
  147. - Pseudocylindrical
  148. - Spheroid
  149. \par Example
  150. \image html ex_eck3.gif
  151. */
  152. template <typename T, typename Parameters>
  153. struct eck3_spheroid : public detail::eck3::base_eck3_spheroid<T, Parameters>
  154. {
  155. inline eck3_spheroid(const Parameters& par) : detail::eck3::base_eck3_spheroid<T, Parameters>(par)
  156. {
  157. detail::eck3::setup_eck3(this->m_par, this->m_proj_parm);
  158. }
  159. };
  160. /*!
  161. \brief Putnins P1 projection
  162. \ingroup projections
  163. \tparam Geographic latlong point type
  164. \tparam Cartesian xy point type
  165. \tparam Parameters parameter type
  166. \par Projection characteristics
  167. - Pseudocylindrical
  168. - Spheroid
  169. \par Example
  170. \image html ex_putp1.gif
  171. */
  172. template <typename T, typename Parameters>
  173. struct putp1_spheroid : public detail::eck3::base_eck3_spheroid<T, Parameters>
  174. {
  175. inline putp1_spheroid(const Parameters& par) : detail::eck3::base_eck3_spheroid<T, Parameters>(par)
  176. {
  177. detail::eck3::setup_putp1(this->m_par, this->m_proj_parm);
  178. }
  179. };
  180. /*!
  181. \brief Wagner VI projection
  182. \ingroup projections
  183. \tparam Geographic latlong point type
  184. \tparam Cartesian xy point type
  185. \tparam Parameters parameter type
  186. \par Projection characteristics
  187. - Pseudocylindrical
  188. - Spheroid
  189. \par Example
  190. \image html ex_wag6.gif
  191. */
  192. template <typename T, typename Parameters>
  193. struct wag6_spheroid : public detail::eck3::base_eck3_spheroid<T, Parameters>
  194. {
  195. inline wag6_spheroid(const Parameters& par) : detail::eck3::base_eck3_spheroid<T, Parameters>(par)
  196. {
  197. detail::eck3::setup_wag6(this->m_par, this->m_proj_parm);
  198. }
  199. };
  200. /*!
  201. \brief Kavraisky VII projection
  202. \ingroup projections
  203. \tparam Geographic latlong point type
  204. \tparam Cartesian xy point type
  205. \tparam Parameters parameter type
  206. \par Projection characteristics
  207. - Pseudocylindrical
  208. - Spheroid
  209. \par Example
  210. \image html ex_kav7.gif
  211. */
  212. template <typename T, typename Parameters>
  213. struct kav7_spheroid : public detail::eck3::base_eck3_spheroid<T, Parameters>
  214. {
  215. inline kav7_spheroid(const Parameters& par) : detail::eck3::base_eck3_spheroid<T, Parameters>(par)
  216. {
  217. detail::eck3::setup_kav7(this->m_par, this->m_proj_parm);
  218. }
  219. };
  220. #ifndef DOXYGEN_NO_DETAIL
  221. namespace detail
  222. {
  223. // Static projection
  224. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::eck3, eck3_spheroid, eck3_spheroid)
  225. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::putp1, putp1_spheroid, putp1_spheroid)
  226. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::wag6, wag6_spheroid, wag6_spheroid)
  227. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::kav7, kav7_spheroid, kav7_spheroid)
  228. // Factory entry(s)
  229. template <typename T, typename Parameters>
  230. class eck3_entry : public detail::factory_entry<T, Parameters>
  231. {
  232. public :
  233. virtual base_v<T, Parameters>* create_new(const Parameters& par) const
  234. {
  235. return new base_v_fi<eck3_spheroid<T, Parameters>, T, Parameters>(par);
  236. }
  237. };
  238. template <typename T, typename Parameters>
  239. class putp1_entry : public detail::factory_entry<T, Parameters>
  240. {
  241. public :
  242. virtual base_v<T, Parameters>* create_new(const Parameters& par) const
  243. {
  244. return new base_v_fi<putp1_spheroid<T, Parameters>, T, Parameters>(par);
  245. }
  246. };
  247. template <typename T, typename Parameters>
  248. class wag6_entry : public detail::factory_entry<T, Parameters>
  249. {
  250. public :
  251. virtual base_v<T, Parameters>* create_new(const Parameters& par) const
  252. {
  253. return new base_v_fi<wag6_spheroid<T, Parameters>, T, Parameters>(par);
  254. }
  255. };
  256. template <typename T, typename Parameters>
  257. class kav7_entry : public detail::factory_entry<T, Parameters>
  258. {
  259. public :
  260. virtual base_v<T, Parameters>* create_new(const Parameters& par) const
  261. {
  262. return new base_v_fi<kav7_spheroid<T, Parameters>, T, Parameters>(par);
  263. }
  264. };
  265. template <typename T, typename Parameters>
  266. inline void eck3_init(detail::base_factory<T, Parameters>& factory)
  267. {
  268. factory.add_to_factory("eck3", new eck3_entry<T, Parameters>);
  269. factory.add_to_factory("putp1", new putp1_entry<T, Parameters>);
  270. factory.add_to_factory("wag6", new wag6_entry<T, Parameters>);
  271. factory.add_to_factory("kav7", new kav7_entry<T, Parameters>);
  272. }
  273. } // namespace detail
  274. #endif // doxygen
  275. } // namespace projections
  276. }} // namespace boost::geometry
  277. #endif // BOOST_GEOMETRY_PROJECTIONS_ECK3_HPP