eck3.hpp 11 KB

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