line_interpolate.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Boost.Geometry
  2. // Copyright (c) 2018, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fysikopoulos, 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_LINE_INTERPOLATE_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_LINE_INTERPOLATE_HPP
  8. #include <boost/geometry/core/assert.hpp>
  9. #include <boost/geometry/core/coordinate_dimension.hpp>
  10. #include <boost/geometry/core/coordinate_type.hpp>
  11. #include <boost/geometry/core/radian_access.hpp>
  12. #include <boost/geometry/srs/spheroid.hpp>
  13. #include <boost/geometry/strategies/line_interpolate.hpp>
  14. #include <boost/geometry/strategies/geographic/parameters.hpp>
  15. #include <boost/geometry/util/select_calculation_type.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. namespace strategy { namespace line_interpolate
  19. {
  20. /*!
  21. \brief Interpolate point on a geographic segment.
  22. \ingroup strategies
  23. \tparam FormulaPolicy The geodesic formulas used internally.
  24. \tparam Spheroid The spheroid model.
  25. \tparam CalculationType \tparam_calculation
  26. \qbk{
  27. [heading See also]
  28. \* [link geometry.reference.algorithms.line_interpolate.line_interpolate_4_with_strategy line_interpolate (with strategy)]
  29. \* [link geometry.reference.srs.srs_spheroid srs::spheroid]
  30. }
  31. */
  32. template
  33. <
  34. typename FormulaPolicy = strategy::andoyer,
  35. typename Spheroid = srs::spheroid<double>,
  36. typename CalculationType = void
  37. >
  38. class geographic
  39. {
  40. public:
  41. geographic()
  42. : m_spheroid()
  43. {}
  44. explicit geographic(Spheroid const& spheroid)
  45. : m_spheroid(spheroid)
  46. {}
  47. // point-point strategy getters
  48. struct distance_pp_strategy
  49. {
  50. typedef distance::geographic<FormulaPolicy, Spheroid, CalculationType> type;
  51. };
  52. inline typename distance_pp_strategy::type get_distance_pp_strategy() const
  53. {
  54. typedef typename distance_pp_strategy::type distance_type;
  55. return distance_type(m_spheroid);
  56. }
  57. template <typename Point, typename Fraction, typename Distance>
  58. inline void apply(Point const& p0,
  59. Point const& p1,
  60. Fraction const& fraction, //fraction of segment
  61. Point & p,
  62. Distance const& distance) const
  63. {
  64. typedef typename select_calculation_type_alt
  65. <
  66. CalculationType,
  67. Point
  68. >::type calc_t;
  69. typedef typename FormulaPolicy::template inverse
  70. <calc_t, false, true, false, false, false> inverse_t;
  71. calc_t azimuth = inverse_t::apply(get_as_radian<0>(p0), get_as_radian<1>(p0),
  72. get_as_radian<0>(p1), get_as_radian<1>(p1),
  73. m_spheroid).azimuth;
  74. typedef typename FormulaPolicy::template direct
  75. <calc_t, true, false, false, false> direct_t;
  76. typename direct_t::result_type
  77. dir_r = direct_t::apply(get_as_radian<0>(p0), get_as_radian<1>(p0),
  78. distance * fraction, azimuth,
  79. m_spheroid);
  80. set_from_radian<0>(p, dir_r.lon2);
  81. set_from_radian<1>(p, dir_r.lat2);
  82. }
  83. private:
  84. Spheroid m_spheroid;
  85. };
  86. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  87. namespace services
  88. {
  89. template <>
  90. struct default_strategy<geographic_tag>
  91. {
  92. typedef strategy::line_interpolate::geographic<> type;
  93. };
  94. } // namespace services
  95. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  96. }} // namespace strategy::line_interpolate
  97. }} // namespace boost::geometry
  98. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_LINE_INTERPOLATE_HPP