bacon.hpp 8.6 KB

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