densify.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Boost.Geometry
  2. // Copyright (c) 2017-2018, 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_GEOGRAPHIC_DENSIFY_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DENSIFY_HPP
  8. #include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
  9. #include <boost/geometry/algorithms/detail/signed_size_type.hpp>
  10. #include <boost/geometry/core/assert.hpp>
  11. #include <boost/geometry/core/coordinate_dimension.hpp>
  12. #include <boost/geometry/core/coordinate_type.hpp>
  13. #include <boost/geometry/core/radian_access.hpp>
  14. #include <boost/geometry/srs/spheroid.hpp>
  15. #include <boost/geometry/strategies/densify.hpp>
  16. #include <boost/geometry/strategies/geographic/parameters.hpp>
  17. #include <boost/geometry/util/select_most_precise.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. namespace strategy { namespace densify
  21. {
  22. /*!
  23. \brief Densification of geographic segment.
  24. \ingroup strategies
  25. \tparam FormulaPolicy The geodesic formulas used internally.
  26. \tparam Spheroid The spheroid model.
  27. \tparam CalculationType \tparam_calculation
  28. \qbk{
  29. [heading See also]
  30. \* [link geometry.reference.algorithms.densify.densify_4_with_strategy densify (with strategy)]
  31. \* [link geometry.reference.srs.srs_spheroid srs::spheroid]
  32. }
  33. */
  34. template
  35. <
  36. typename FormulaPolicy = strategy::andoyer,
  37. typename Spheroid = srs::spheroid<double>,
  38. typename CalculationType = void
  39. >
  40. class geographic
  41. {
  42. public:
  43. geographic()
  44. : m_spheroid()
  45. {}
  46. explicit geographic(Spheroid const& spheroid)
  47. : m_spheroid(spheroid)
  48. {}
  49. template <typename Point, typename AssignPolicy, typename T>
  50. inline void apply(Point const& p0, Point const& p1, AssignPolicy & policy, T const& length_threshold) const
  51. {
  52. typedef typename AssignPolicy::point_type out_point_t;
  53. typedef typename select_most_precise
  54. <
  55. typename coordinate_type<Point>::type,
  56. typename coordinate_type<out_point_t>::type,
  57. CalculationType
  58. >::type calc_t;
  59. typedef typename FormulaPolicy::template direct<calc_t, true, false, false, false> direct_t;
  60. typedef typename FormulaPolicy::template inverse<calc_t, true, true, false, false, false> inverse_t;
  61. typename inverse_t::result_type
  62. inv_r = inverse_t::apply(get_as_radian<0>(p0), get_as_radian<1>(p0),
  63. get_as_radian<0>(p1), get_as_radian<1>(p1),
  64. m_spheroid);
  65. BOOST_GEOMETRY_ASSERT(length_threshold > T(0));
  66. signed_size_type n = signed_size_type(inv_r.distance / length_threshold);
  67. if (n <= 0)
  68. return;
  69. calc_t step = inv_r.distance / (n + 1);
  70. calc_t current = step;
  71. for (signed_size_type i = 0 ; i < n ; ++i, current += step)
  72. {
  73. typename direct_t::result_type
  74. dir_r = direct_t::apply(get_as_radian<0>(p0), get_as_radian<1>(p0),
  75. current, inv_r.azimuth,
  76. m_spheroid);
  77. out_point_t p;
  78. set_from_radian<0>(p, dir_r.lon2);
  79. set_from_radian<1>(p, dir_r.lat2);
  80. geometry::detail::conversion::point_to_point
  81. <
  82. Point, out_point_t,
  83. 2, dimension<out_point_t>::value
  84. >::apply(p0, p);
  85. policy.apply(p);
  86. }
  87. }
  88. private:
  89. Spheroid m_spheroid;
  90. };
  91. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  92. namespace services
  93. {
  94. template <>
  95. struct default_strategy<geographic_tag>
  96. {
  97. typedef strategy::densify::geographic<> type;
  98. };
  99. } // namespace services
  100. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  101. }} // namespace strategy::densify
  102. }} // namespace boost::geometry
  103. #endif // BOOST_GEOMETRY_ALGORITHMS_DENSIFY_HPP