eck3.hpp 10.0 KB

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