geographic.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Boost.Geometry
  2. // Copyright (c) 2020-2021, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_STRATEGIES_AREA_GEOGRAPHIC_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_AREA_GEOGRAPHIC_HPP
  8. #include <boost/geometry/strategy/geographic/area.hpp>
  9. #include <boost/geometry/strategy/geographic/area_box.hpp>
  10. #include <boost/geometry/strategies/area/services.hpp>
  11. #include <boost/geometry/strategies/detail.hpp>
  12. namespace boost { namespace geometry
  13. {
  14. namespace strategies { namespace area
  15. {
  16. template
  17. <
  18. typename FormulaPolicy = strategy::andoyer,
  19. typename Spheroid = srs::spheroid<double>,
  20. typename CalculationType = void
  21. >
  22. class geographic
  23. : public strategies::detail::geographic_base<Spheroid>
  24. {
  25. using base_t = strategies::detail::geographic_base<Spheroid>;
  26. public:
  27. geographic() = default;
  28. explicit geographic(Spheroid const& spheroid)
  29. : base_t(spheroid)
  30. {}
  31. template <typename Geometry>
  32. auto area(Geometry const&,
  33. std::enable_if_t<! util::is_box<Geometry>::value> * = nullptr) const
  34. {
  35. return strategy::area::geographic
  36. <
  37. FormulaPolicy,
  38. strategy::default_order<FormulaPolicy>::value,
  39. Spheroid, CalculationType
  40. >(base_t::m_spheroid);
  41. }
  42. template <typename Geometry>
  43. auto area(Geometry const&,
  44. std::enable_if_t<util::is_box<Geometry>::value> * = nullptr) const
  45. {
  46. return strategy::area::geographic_box
  47. <
  48. Spheroid, CalculationType
  49. >(base_t::m_spheroid);
  50. }
  51. };
  52. namespace services
  53. {
  54. template <typename Geometry>
  55. struct default_strategy<Geometry, geographic_tag>
  56. {
  57. using type = strategies::area::geographic<>;
  58. };
  59. template <typename FP, std::size_t SO, typename S, typename CT>
  60. struct strategy_converter<strategy::area::geographic<FP, SO, S, CT> >
  61. {
  62. struct altered_strategy
  63. : strategies::area::geographic<FP, S, CT>
  64. {
  65. explicit altered_strategy(S const& spheroid)
  66. : strategies::area::geographic<FP, S, CT>(spheroid)
  67. {}
  68. using strategies::area::geographic<FP, S, CT>::area;
  69. template <typename Geometry>
  70. auto area(Geometry const&,
  71. std::enable_if_t<! util::is_box<Geometry>::value> * = nullptr) const
  72. {
  73. return strategy::area::geographic<FP, SO, S, CT>(this->m_spheroid);
  74. }
  75. };
  76. static auto get(strategy::area::geographic<FP, SO, S, CT> const& strategy)
  77. {
  78. return altered_strategy(strategy.model());
  79. }
  80. };
  81. } // namespace services
  82. }} // namespace strategies::area
  83. }} // namespace boost::geometry
  84. #endif // BOOST_GEOMETRY_STRATEGIES_AREA_GEOGRAPHIC_HPP