geographic.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Boost.Geometry
  2. // Copyright (c) 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_SIMPLIFY_GEOGRAPHIC_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_SIMPLIFY_GEOGRAPHIC_HPP
  8. #include <boost/geometry/strategies/detail.hpp>
  9. #include <boost/geometry/strategies/distance/detail.hpp>
  10. #include <boost/geometry/strategies/simplify/services.hpp>
  11. #include <boost/geometry/strategies/agnostic/simplify_douglas_peucker.hpp>
  12. #include <boost/geometry/strategies/geographic/distance_cross_track.hpp>
  13. #include <boost/geometry/strategies/spherical/point_in_point.hpp>
  14. #include <boost/geometry/strategy/geographic/area.hpp>
  15. namespace boost { namespace geometry
  16. {
  17. namespace strategies { namespace simplify
  18. {
  19. template
  20. <
  21. typename FormulaPolicy = strategy::andoyer,
  22. typename Spheroid = srs::spheroid<double>,
  23. typename CalculationType = void
  24. >
  25. class geographic
  26. : public strategies::detail::geographic_base<Spheroid>
  27. {
  28. using base_t = strategies::detail::geographic_base<Spheroid>;
  29. public:
  30. geographic() = default;
  31. explicit geographic(Spheroid const& spheroid)
  32. : base_t(spheroid)
  33. {}
  34. // TODO: Replace this if calculate_point_order() is used in simplify
  35. template <typename Geometry>
  36. auto area(Geometry const&) const
  37. {
  38. return strategy::area::geographic
  39. <
  40. FormulaPolicy,
  41. strategy::default_order<FormulaPolicy>::value,
  42. Spheroid,
  43. CalculationType
  44. >(base_t::m_spheroid);
  45. }
  46. // For perimeter()
  47. template <typename Geometry1, typename Geometry2>
  48. auto distance(Geometry1 const&, Geometry2 const&,
  49. distance::detail::enable_if_pp_t<Geometry1, Geometry2> * = nullptr) const
  50. {
  51. return strategy::distance::geographic
  52. <
  53. FormulaPolicy, Spheroid, CalculationType
  54. >(base_t::m_spheroid);
  55. }
  56. // For douglas_peucker
  57. template <typename Geometry1, typename Geometry2>
  58. auto distance(Geometry1 const&, Geometry2 const&,
  59. distance::detail::enable_if_ps_t<Geometry1, Geometry2> * = nullptr) const
  60. {
  61. return strategy::distance::geographic_cross_track
  62. <
  63. FormulaPolicy, Spheroid, CalculationType
  64. >(base_t::m_spheroid);
  65. }
  66. // For equals()
  67. template <typename Geometry1, typename Geometry2>
  68. static auto relate(Geometry1 const&, Geometry2 const&,
  69. std::enable_if_t
  70. <
  71. util::is_pointlike<Geometry1>::value
  72. && util::is_pointlike<Geometry2>::value
  73. > * = nullptr)
  74. {
  75. return strategy::within::spherical_point_point();
  76. }
  77. };
  78. namespace services
  79. {
  80. template <typename Geometry>
  81. struct default_strategy<Geometry, geographic_tag>
  82. {
  83. using type = strategies::simplify::geographic<>;
  84. };
  85. template <typename P, typename FP, typename S, typename CT>
  86. struct strategy_converter
  87. <
  88. strategy::simplify::douglas_peucker
  89. <
  90. P,
  91. strategy::distance::geographic_cross_track<FP, S, CT>
  92. >
  93. >
  94. {
  95. template <typename Strategy>
  96. static auto get(Strategy const& )
  97. {
  98. return strategies::simplify::geographic<FP, S, CT>();
  99. }
  100. };
  101. } // namespace services
  102. }} // namespace strategies::simplify
  103. }} // namespace boost::geometry
  104. #endif // BOOST_GEOMETRY_STRATEGIES_SIMPLIFY_GEOGRAPHIC_HPP