bacon.hpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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_BACON_HPP
  31. #define BOOST_GEOMETRY_PROJECTIONS_BACON_HPP
  32. #include <boost/geometry/util/math.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. namespace boost { namespace geometry
  38. {
  39. namespace projections
  40. {
  41. #ifndef DOXYGEN_NO_DETAIL
  42. namespace detail { namespace bacon
  43. {
  44. //static const double half_pi_sqr = 2.46740110027233965467;
  45. static const double epsilon = 1e-10;
  46. struct par_bacon
  47. {
  48. bool bacn;
  49. bool ortl;
  50. };
  51. template <typename T, typename Parameters>
  52. struct base_bacon_spheroid
  53. {
  54. par_bacon m_proj_parm;
  55. // FORWARD(s_forward) spheroid
  56. // Project coordinates from geographic (lon, lat) to cartesian (x, y)
  57. inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
  58. {
  59. static const T half_pi = detail::half_pi<T>();
  60. static const T half_pi_sqr = detail::half_pi_sqr<T>();
  61. T ax, f;
  62. xy_y = this->m_proj_parm.bacn ? half_pi * sin(lp_lat) : lp_lat;
  63. if ((ax = fabs(lp_lon)) >= epsilon) {
  64. if (this->m_proj_parm.ortl && ax >= half_pi)
  65. xy_x = sqrt(half_pi_sqr - lp_lat * lp_lat + epsilon) + ax - half_pi;
  66. else {
  67. f = 0.5 * (half_pi_sqr / ax + ax);
  68. xy_x = ax - f + sqrt(f * f - xy_y * xy_y);
  69. }
  70. if (lp_lon < 0.) xy_x = - xy_x;
  71. } else
  72. xy_x = 0.;
  73. }
  74. static inline std::string get_name()
  75. {
  76. return "bacon_spheroid";
  77. }
  78. };
  79. // Apian Globular I
  80. template <typename Parameters>
  81. inline void setup_apian(Parameters& par, par_bacon& proj_parm)
  82. {
  83. proj_parm.bacn = proj_parm.ortl = false;
  84. par.es = 0.;
  85. }
  86. // Ortelius Oval
  87. template <typename Parameters>
  88. inline void setup_ortel(Parameters& par, par_bacon& proj_parm)
  89. {
  90. proj_parm.bacn = false;
  91. proj_parm.ortl = true;
  92. par.es = 0.;
  93. }
  94. // Bacon Globular
  95. template <typename Parameters>
  96. inline void setup_bacon(Parameters& par, par_bacon& proj_parm)
  97. {
  98. proj_parm.bacn = true;
  99. proj_parm.ortl = false;
  100. par.es = 0.;
  101. }
  102. }} // namespace detail::bacon
  103. #endif // doxygen
  104. /*!
  105. \brief Apian Globular I projection
  106. \ingroup projections
  107. \tparam Geographic latlong point type
  108. \tparam Cartesian xy point type
  109. \tparam Parameters parameter type
  110. \par Projection characteristics
  111. - Miscellaneous
  112. - Spheroid
  113. - no inverse
  114. \par Example
  115. \image html ex_apian.gif
  116. */
  117. template <typename T, typename Parameters>
  118. struct apian_spheroid : public detail::bacon::base_bacon_spheroid<T, Parameters>
  119. {
  120. template <typename Params>
  121. inline apian_spheroid(Params const& , Parameters & par)
  122. {
  123. detail::bacon::setup_apian(par, this->m_proj_parm);
  124. }
  125. };
  126. /*!
  127. \brief Ortelius Oval projection
  128. \ingroup projections
  129. \tparam Geographic latlong point type
  130. \tparam Cartesian xy point type
  131. \tparam Parameters parameter type
  132. \par Projection characteristics
  133. - Miscellaneous
  134. - Spheroid
  135. - no inverse
  136. \par Example
  137. \image html ex_ortel.gif
  138. */
  139. template <typename T, typename Parameters>
  140. struct ortel_spheroid : public detail::bacon::base_bacon_spheroid<T, Parameters>
  141. {
  142. template <typename Params>
  143. inline ortel_spheroid(Params const& , Parameters & par)
  144. {
  145. detail::bacon::setup_ortel(par, this->m_proj_parm);
  146. }
  147. };
  148. /*!
  149. \brief Bacon Globular projection
  150. \ingroup projections
  151. \tparam Geographic latlong point type
  152. \tparam Cartesian xy point type
  153. \tparam Parameters parameter type
  154. \par Projection characteristics
  155. - Miscellaneous
  156. - Spheroid
  157. - no inverse
  158. \par Example
  159. \image html ex_bacon.gif
  160. */
  161. template <typename T, typename Parameters>
  162. struct bacon_spheroid : public detail::bacon::base_bacon_spheroid<T, Parameters>
  163. {
  164. template <typename Params>
  165. inline bacon_spheroid(Params const& , Parameters & par)
  166. {
  167. detail::bacon::setup_bacon(par, this->m_proj_parm);
  168. }
  169. };
  170. #ifndef DOXYGEN_NO_DETAIL
  171. namespace detail
  172. {
  173. // Static projection
  174. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(srs::spar::proj_apian, apian_spheroid)
  175. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(srs::spar::proj_bacon, bacon_spheroid)
  176. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(srs::spar::proj_ortel, ortel_spheroid)
  177. // Factory entry(s)
  178. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(apian_entry, apian_spheroid)
  179. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(ortel_entry, ortel_spheroid)
  180. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(bacon_entry, bacon_spheroid)
  181. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(bacon_init)
  182. {
  183. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(apian, apian_entry)
  184. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(ortel, ortel_entry)
  185. BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(bacon, bacon_entry)
  186. }
  187. } // namespace detail
  188. #endif // doxygen
  189. } // namespace projections
  190. }} // namespace boost::geometry
  191. #endif // BOOST_GEOMETRY_PROJECTIONS_BACON_HPP