bacon.hpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 srs { namespace par4
  40. {
  41. struct apian {};
  42. struct ortel {};
  43. struct bacon {};
  44. }} //namespace srs::par4
  45. namespace projections
  46. {
  47. #ifndef DOXYGEN_NO_DETAIL
  48. namespace detail { namespace bacon
  49. {
  50. //static const double half_pi_sqr = 2.46740110027233965467;
  51. static const double epsilon = 1e-10;
  52. struct par_bacon
  53. {
  54. int bacn;
  55. int ortl;
  56. };
  57. // template class, using CRTP to implement forward/inverse
  58. template <typename T, typename Parameters>
  59. struct base_bacon_spheroid
  60. : public base_t_f<base_bacon_spheroid<T, Parameters>, T, Parameters>
  61. {
  62. par_bacon m_proj_parm;
  63. inline base_bacon_spheroid(const Parameters& par)
  64. : base_t_f<base_bacon_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. static const T half_pi = detail::half_pi<T>();
  71. static const T half_pi_sqr = detail::half_pi_sqr<T>();
  72. T ax, f;
  73. xy_y = this->m_proj_parm.bacn ? half_pi * sin(lp_lat) : lp_lat;
  74. if ((ax = fabs(lp_lon)) >= epsilon) {
  75. if (this->m_proj_parm.ortl && ax >= half_pi)
  76. xy_x = sqrt(half_pi_sqr - lp_lat * lp_lat + epsilon) + ax - half_pi;
  77. else {
  78. f = 0.5 * (half_pi_sqr / ax + ax);
  79. xy_x = ax - f + sqrt(f * f - xy_y * xy_y);
  80. }
  81. if (lp_lon < 0.) xy_x = - xy_x;
  82. } else
  83. xy_x = 0.;
  84. }
  85. static inline std::string get_name()
  86. {
  87. return "bacon_spheroid";
  88. }
  89. };
  90. // Apian Globular I
  91. template <typename Parameters>
  92. inline void setup_apian(Parameters& par, par_bacon& proj_parm)
  93. {
  94. proj_parm.bacn = proj_parm.ortl = 0;
  95. par.es = 0.;
  96. }
  97. // Ortelius Oval
  98. template <typename Parameters>
  99. inline void setup_ortel(Parameters& par, par_bacon& proj_parm)
  100. {
  101. proj_parm.bacn = 0;
  102. proj_parm.ortl = 1;
  103. par.es = 0.;
  104. }
  105. // Bacon Globular
  106. template <typename Parameters>
  107. inline void setup_bacon(Parameters& par, par_bacon& proj_parm)
  108. {
  109. proj_parm.bacn = 1;
  110. proj_parm.ortl = 0;
  111. par.es = 0.;
  112. }
  113. }} // namespace detail::bacon
  114. #endif // doxygen
  115. /*!
  116. \brief Apian Globular I projection
  117. \ingroup projections
  118. \tparam Geographic latlong point type
  119. \tparam Cartesian xy point type
  120. \tparam Parameters parameter type
  121. \par Projection characteristics
  122. - Miscellaneous
  123. - Spheroid
  124. - no inverse
  125. \par Example
  126. \image html ex_apian.gif
  127. */
  128. template <typename T, typename Parameters>
  129. struct apian_spheroid : public detail::bacon::base_bacon_spheroid<T, Parameters>
  130. {
  131. inline apian_spheroid(const Parameters& par) : detail::bacon::base_bacon_spheroid<T, Parameters>(par)
  132. {
  133. detail::bacon::setup_apian(this->m_par, this->m_proj_parm);
  134. }
  135. };
  136. /*!
  137. \brief Ortelius Oval projection
  138. \ingroup projections
  139. \tparam Geographic latlong point type
  140. \tparam Cartesian xy point type
  141. \tparam Parameters parameter type
  142. \par Projection characteristics
  143. - Miscellaneous
  144. - Spheroid
  145. - no inverse
  146. \par Example
  147. \image html ex_ortel.gif
  148. */
  149. template <typename T, typename Parameters>
  150. struct ortel_spheroid : public detail::bacon::base_bacon_spheroid<T, Parameters>
  151. {
  152. inline ortel_spheroid(const Parameters& par) : detail::bacon::base_bacon_spheroid<T, Parameters>(par)
  153. {
  154. detail::bacon::setup_ortel(this->m_par, this->m_proj_parm);
  155. }
  156. };
  157. /*!
  158. \brief Bacon Globular projection
  159. \ingroup projections
  160. \tparam Geographic latlong point type
  161. \tparam Cartesian xy point type
  162. \tparam Parameters parameter type
  163. \par Projection characteristics
  164. - Miscellaneous
  165. - Spheroid
  166. - no inverse
  167. \par Example
  168. \image html ex_bacon.gif
  169. */
  170. template <typename T, typename Parameters>
  171. struct bacon_spheroid : public detail::bacon::base_bacon_spheroid<T, Parameters>
  172. {
  173. inline bacon_spheroid(const Parameters& par) : 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::par4::apian, apian_spheroid, apian_spheroid)
  183. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::bacon, bacon_spheroid, bacon_spheroid)
  184. BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::ortel, ortel_spheroid, ortel_spheroid)
  185. // Factory entry(s)
  186. template <typename T, typename Parameters>
  187. class apian_entry : public detail::factory_entry<T, Parameters>
  188. {
  189. public :
  190. virtual base_v<T, Parameters>* create_new(const Parameters& par) const
  191. {
  192. return new base_v_f<apian_spheroid<T, Parameters>, T, Parameters>(par);
  193. }
  194. };
  195. template <typename T, typename Parameters>
  196. class ortel_entry : public detail::factory_entry<T, Parameters>
  197. {
  198. public :
  199. virtual base_v<T, Parameters>* create_new(const Parameters& par) const
  200. {
  201. return new base_v_f<ortel_spheroid<T, Parameters>, T, Parameters>(par);
  202. }
  203. };
  204. template <typename T, typename Parameters>
  205. class bacon_entry : public detail::factory_entry<T, Parameters>
  206. {
  207. public :
  208. virtual base_v<T, Parameters>* create_new(const Parameters& par) const
  209. {
  210. return new base_v_f<bacon_spheroid<T, Parameters>, T, Parameters>(par);
  211. }
  212. };
  213. template <typename T, typename Parameters>
  214. inline void bacon_init(detail::base_factory<T, Parameters>& factory)
  215. {
  216. factory.add_to_factory("apian", new apian_entry<T, Parameters>);
  217. factory.add_to_factory("ortel", new ortel_entry<T, Parameters>);
  218. factory.add_to_factory("bacon", new bacon_entry<T, Parameters>);
  219. }
  220. } // namespace detail
  221. #endif // doxygen
  222. } // namespace projections
  223. }} // namespace boost::geometry
  224. #endif // BOOST_GEOMETRY_PROJECTIONS_BACON_HPP