geographic.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. // Boost.Geometry
  2. // Copyright (c) 2020, 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_INDEX_GEOGRAPHIC_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_INDEX_GEOGRAPHIC_HPP
  8. #include <boost/geometry/strategies/index/services.hpp>
  9. #include <boost/geometry/strategies/relate/geographic.hpp>
  10. // TEMP - move to strategy
  11. #include <boost/geometry/strategies/geographic/distance.hpp>
  12. #include <boost/geometry/strategies/geographic/distance_andoyer.hpp>
  13. #include <boost/geometry/strategies/geographic/distance_cross_track.hpp>
  14. #include <boost/geometry/strategies/geographic/distance_cross_track_box_box.hpp>
  15. #include <boost/geometry/strategies/geographic/distance_cross_track_point_box.hpp>
  16. #include <boost/geometry/strategies/geographic/distance_segment_box.hpp>
  17. #include <boost/geometry/strategies/geographic/distance_thomas.hpp>
  18. #include <boost/geometry/strategies/geographic/distance_vincenty.hpp>
  19. namespace boost { namespace geometry { namespace strategies { namespace index
  20. {
  21. template
  22. <
  23. typename FormulaPolicy = strategy::andoyer,
  24. // TODO: Is SeriesOrder argument needed here?
  25. std::size_t SeriesOrder = strategy::default_order<FormulaPolicy>::value,
  26. typename Spheroid = srs::spheroid<double>,
  27. typename CalculationType = void
  28. >
  29. class geographic
  30. : public relate::geographic<FormulaPolicy, SeriesOrder, Spheroid, CalculationType>
  31. {
  32. typedef relate::geographic<FormulaPolicy, SeriesOrder, Spheroid, CalculationType> base_t;
  33. public:
  34. geographic()
  35. : base_t()
  36. {}
  37. explicit geographic(Spheroid const& spheroid)
  38. : base_t(spheroid)
  39. {}
  40. template <typename Geometry1, typename Geometry2>
  41. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  42. std::enable_if_t
  43. <
  44. util::is_pointlike<Geometry1>::value
  45. && util::is_pointlike<Geometry2>::value
  46. > * = nullptr) const
  47. {
  48. return geometry::strategy::distance::geographic
  49. <
  50. FormulaPolicy, Spheroid, CalculationType
  51. >(base_t::m_spheroid);
  52. }
  53. template <typename Geometry1, typename Geometry2>
  54. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  55. std::enable_if_t
  56. <
  57. (util::is_pointlike<Geometry1>::value
  58. && util::is_segment<Geometry2>::value)
  59. || (util::is_segment<Geometry1>::value
  60. && util::is_pointlike<Geometry2>::value)
  61. > * = nullptr) const
  62. {
  63. return geometry::strategy::distance::geographic_cross_track
  64. <
  65. FormulaPolicy, Spheroid, CalculationType
  66. >(base_t::m_spheroid);
  67. }
  68. template <typename Geometry1, typename Geometry2>
  69. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  70. std::enable_if_t
  71. <
  72. (util::is_pointlike<Geometry1>::value
  73. && util::is_box<Geometry2>::value)
  74. || (util::is_box<Geometry1>::value
  75. && util::is_pointlike<Geometry2>::value)
  76. > * = nullptr) const
  77. {
  78. return geometry::strategy::distance::geographic_cross_track_point_box
  79. <
  80. FormulaPolicy, Spheroid, CalculationType
  81. >(base_t::m_spheroid);
  82. }
  83. template <typename Geometry1, typename Geometry2>
  84. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  85. std::enable_if_t
  86. <
  87. (util::is_segment<Geometry1>::value
  88. && util::is_box<Geometry2>::value)
  89. || (util::is_box<Geometry1>::value
  90. && util::is_segment<Geometry2>::value)
  91. > * = nullptr) const
  92. {
  93. return geometry::strategy::distance::geographic_segment_box
  94. <
  95. FormulaPolicy, Spheroid, CalculationType
  96. >(base_t::m_spheroid);
  97. }
  98. template <typename Geometry1, typename Geometry2>
  99. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  100. std::enable_if_t
  101. <
  102. util::is_segment<Geometry1>::value
  103. && util::is_segment<Geometry2>::value
  104. > * = nullptr) const
  105. {
  106. return geometry::strategy::distance::geographic_cross_track
  107. <
  108. FormulaPolicy, Spheroid, CalculationType
  109. >(base_t::m_spheroid);
  110. }
  111. };
  112. namespace services
  113. {
  114. template <typename Geometry>
  115. struct default_strategy<Geometry, geographic_tag>
  116. {
  117. using type = strategies::index::geographic<>;
  118. };
  119. // TEMP - needed in distance until umbrella strategies are supported
  120. template <typename FormulaPolicy, typename Spheroid, typename CalculationType>
  121. struct strategy_converter<strategy::distance::geographic_cross_track<FormulaPolicy, Spheroid, CalculationType>>
  122. {
  123. static auto get(strategy::distance::geographic_cross_track<FormulaPolicy, Spheroid, CalculationType> const& strategy)
  124. {
  125. return strategies::index::geographic
  126. <
  127. FormulaPolicy,
  128. strategy::default_order<FormulaPolicy>::value,
  129. Spheroid,
  130. CalculationType
  131. >(strategy.model());
  132. }
  133. };
  134. // TEMP - needed in distance until umbrella strategies are supported
  135. template <typename FormulaPolicy, typename Spheroid, typename CalculationType, bool Bisection, bool EnableClosestPoint>
  136. struct strategy_converter<strategy::distance::detail::geographic_cross_track<FormulaPolicy, Spheroid, CalculationType, Bisection, EnableClosestPoint>>
  137. {
  138. typedef strategies::index::geographic
  139. <
  140. FormulaPolicy,
  141. strategy::default_order<FormulaPolicy>::value,
  142. Spheroid,
  143. CalculationType
  144. > base_strategy;
  145. struct altered_strategy : base_strategy
  146. {
  147. explicit altered_strategy(Spheroid const& spheroid)
  148. : base_strategy(spheroid)
  149. {}
  150. // It seems that this declaration is needed because comparable_distance
  151. // is not static function.
  152. using base_strategy::comparable_distance;
  153. template <typename Geometry1, typename Geometry2>
  154. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  155. std::enable_if_t
  156. <
  157. (util::is_pointlike<Geometry1>::value
  158. && util::is_segment<Geometry2>::value)
  159. || (util::is_segment<Geometry1>::value
  160. && util::is_pointlike<Geometry2>::value)
  161. > * = nullptr) const
  162. {
  163. return geometry::strategy::distance::detail::geographic_cross_track
  164. <
  165. FormulaPolicy, Spheroid, CalculationType, Bisection, EnableClosestPoint
  166. >(base_strategy::m_spheroid);
  167. }
  168. template <typename Geometry1, typename Geometry2>
  169. auto comparable_distance(Geometry1 const&, Geometry2 const&,
  170. std::enable_if_t
  171. <
  172. util::is_segment<Geometry1>::value
  173. && util::is_segment<Geometry2>::value
  174. > * = nullptr) const
  175. {
  176. return geometry::strategy::distance::detail::geographic_cross_track
  177. <
  178. FormulaPolicy, Spheroid, CalculationType, Bisection, EnableClosestPoint
  179. >(base_strategy::m_spheroid);
  180. }
  181. };
  182. static auto get(strategy::distance::detail::geographic_cross_track<FormulaPolicy, Spheroid, CalculationType, Bisection, EnableClosestPoint> const& strategy)
  183. {
  184. return altered_strategy(strategy.model());
  185. }
  186. };
  187. // TEMP - needed in distance until umbrella strategies are supported
  188. template <typename FormulaPolicy, typename Spheroid, typename CalculationType>
  189. struct strategy_converter<strategy::distance::geographic<FormulaPolicy, Spheroid, CalculationType>>
  190. {
  191. static auto get(strategy::distance::geographic<FormulaPolicy, Spheroid, CalculationType> const& strategy)
  192. {
  193. return strategies::index::geographic
  194. <
  195. FormulaPolicy,
  196. strategy::default_order<FormulaPolicy>::value,
  197. Spheroid,
  198. CalculationType
  199. >(strategy.model());
  200. }
  201. };
  202. // TEMP - needed in distance until umbrella strategies are supported
  203. template <typename Spheroid, typename CalculationType>
  204. struct strategy_converter<strategy::distance::andoyer<Spheroid, CalculationType>>
  205. {
  206. static auto get(strategy::distance::andoyer<Spheroid, CalculationType> const& strategy)
  207. {
  208. return strategies::index::geographic
  209. <
  210. strategy::andoyer,
  211. strategy::default_order<strategy::andoyer>::value,
  212. Spheroid,
  213. CalculationType
  214. >(strategy.model());
  215. }
  216. };
  217. // TEMP - needed in distance until umbrella strategies are supported
  218. template <typename Spheroid, typename CalculationType>
  219. struct strategy_converter<strategy::distance::thomas<Spheroid, CalculationType>>
  220. {
  221. static auto get(strategy::distance::thomas<Spheroid, CalculationType> const& strategy)
  222. {
  223. return strategies::index::geographic
  224. <
  225. strategy::thomas,
  226. strategy::default_order<strategy::thomas>::value,
  227. Spheroid,
  228. CalculationType
  229. >(strategy.model());
  230. }
  231. };
  232. // TEMP - needed in distance until umbrella strategies are supported
  233. template <typename Spheroid, typename CalculationType>
  234. struct strategy_converter<strategy::distance::vincenty<Spheroid, CalculationType>>
  235. {
  236. static auto get(strategy::distance::vincenty<Spheroid, CalculationType> const& strategy)
  237. {
  238. return strategies::index::geographic
  239. <
  240. strategy::vincenty,
  241. strategy::default_order<strategy::vincenty>::value,
  242. Spheroid,
  243. CalculationType
  244. >(strategy.model());
  245. }
  246. };
  247. } // namespace services
  248. }}}} // namespace boost::geometry::strategy::index
  249. #endif // BOOST_GEOMETRY_STRATEGIES_INDEX_GEOGRAPHIC_HPP