geographic.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. // Boost.Geometry
  2. // Copyright (c) 2020-2023, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_STRATEGIES_RELATE_GEOGRAPHIC_HPP
  8. #define BOOST_GEOMETRY_STRATEGIES_RELATE_GEOGRAPHIC_HPP
  9. // TEMP - move to strategy
  10. #include <boost/geometry/strategies/agnostic/point_in_box_by_side.hpp>
  11. #include <boost/geometry/strategies/cartesian/box_in_box.hpp>
  12. #include <boost/geometry/strategies/geographic/intersection.hpp>
  13. #include <boost/geometry/strategies/geographic/point_in_poly_winding.hpp>
  14. #include <boost/geometry/strategies/spherical/point_in_point.hpp>
  15. #include <boost/geometry/strategies/spherical/disjoint_box_box.hpp>
  16. #include <boost/geometry/strategies/envelope/geographic.hpp>
  17. #include <boost/geometry/strategies/relate/services.hpp>
  18. #include <boost/geometry/strategies/detail.hpp>
  19. #include <boost/geometry/strategy/geographic/area.hpp>
  20. #include <boost/geometry/strategy/geographic/area_box.hpp>
  21. #include <boost/geometry/util/type_traits.hpp>
  22. namespace boost { namespace geometry
  23. {
  24. namespace strategies { namespace relate
  25. {
  26. template
  27. <
  28. typename FormulaPolicy = strategy::andoyer,
  29. typename Spheroid = srs::spheroid<double>,
  30. typename CalculationType = void
  31. >
  32. class geographic
  33. : public strategies::envelope::geographic<FormulaPolicy, Spheroid, CalculationType>
  34. {
  35. using base_t = strategies::envelope::geographic<FormulaPolicy, Spheroid, CalculationType>;
  36. public:
  37. geographic() = default;
  38. explicit geographic(Spheroid const& spheroid)
  39. : base_t(spheroid)
  40. {}
  41. // area
  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
  47. <
  48. FormulaPolicy,
  49. strategy::default_order<FormulaPolicy>::value,
  50. Spheroid, CalculationType
  51. >(base_t::m_spheroid);
  52. }
  53. template <typename Geometry>
  54. auto area(Geometry const&,
  55. std::enable_if_t<util::is_box<Geometry>::value> * = nullptr) const
  56. {
  57. return strategy::area::geographic_box
  58. <
  59. Spheroid, CalculationType
  60. >(base_t::m_spheroid);
  61. }
  62. // covered_by
  63. template <typename Geometry1, typename Geometry2>
  64. static auto covered_by(Geometry1 const&, Geometry2 const&,
  65. std::enable_if_t
  66. <
  67. util::is_pointlike<Geometry1>::value
  68. && util::is_box<Geometry2>::value
  69. > * = nullptr)
  70. {
  71. return strategy::covered_by::spherical_point_box();
  72. }
  73. template <typename Geometry1, typename Geometry2>
  74. static auto covered_by(Geometry1 const&, Geometry2 const&,
  75. std::enable_if_t
  76. <
  77. util::is_box<Geometry1>::value
  78. && util::is_box<Geometry2>::value
  79. > * = nullptr)
  80. {
  81. return strategy::covered_by::spherical_box_box();
  82. }
  83. // disjoint
  84. template <typename Geometry1, typename Geometry2>
  85. static auto disjoint(Geometry1 const&, Geometry2 const&,
  86. std::enable_if_t
  87. <
  88. util::is_box<Geometry1>::value
  89. && util::is_box<Geometry2>::value
  90. > * = nullptr)
  91. {
  92. return strategy::disjoint::spherical_box_box();
  93. }
  94. template <typename Geometry1, typename Geometry2>
  95. auto disjoint(Geometry1 const&, Geometry2 const&,
  96. std::enable_if_t
  97. <
  98. util::is_segment<Geometry1>::value
  99. && util::is_box<Geometry2>::value
  100. > * = nullptr) const
  101. {
  102. // NOTE: Inconsistent name
  103. // The only disjoint(Seg, Box) strategy that takes CalculationType.
  104. return strategy::disjoint::segment_box_geographic
  105. <
  106. FormulaPolicy, Spheroid, CalculationType
  107. >(base_t::m_spheroid);
  108. }
  109. // relate
  110. template <typename Geometry1, typename Geometry2>
  111. static auto relate(Geometry1 const&, Geometry2 const&,
  112. std::enable_if_t
  113. <
  114. util::is_pointlike<Geometry1>::value
  115. && util::is_pointlike<Geometry2>::value
  116. > * = nullptr)
  117. {
  118. return strategy::within::spherical_point_point();
  119. }
  120. template <typename Geometry1, typename Geometry2>
  121. auto relate(Geometry1 const&, Geometry2 const&,
  122. std::enable_if_t
  123. <
  124. util::is_pointlike<Geometry1>::value
  125. && ( util::is_linear<Geometry2>::value
  126. || util::is_polygonal<Geometry2>::value )
  127. > * = nullptr) const
  128. {
  129. return strategy::within::geographic_winding
  130. <
  131. void, void, FormulaPolicy, Spheroid, CalculationType
  132. >(base_t::m_spheroid);
  133. }
  134. //template <typename Geometry1, typename Geometry2>
  135. auto relate(/*Geometry1 const&, Geometry2 const&,
  136. std::enable_if_t
  137. <
  138. ( util::is_linear<Geometry1>::value
  139. || util::is_polygonal<Geometry1>::value )
  140. && ( util::is_linear<Geometry2>::value
  141. || util::is_polygonal<Geometry2>::value )
  142. > * = nullptr*/) const
  143. {
  144. return strategy::intersection::geographic_segments
  145. <
  146. FormulaPolicy,
  147. strategy::default_order<FormulaPolicy>::value,
  148. Spheroid, CalculationType
  149. >(base_t::m_spheroid);
  150. }
  151. // side
  152. auto side() const
  153. {
  154. return strategy::side::geographic
  155. <
  156. FormulaPolicy, Spheroid, CalculationType
  157. >(base_t::m_spheroid);
  158. }
  159. // within
  160. template <typename Geometry1, typename Geometry2>
  161. static auto within(Geometry1 const&, Geometry2 const&,
  162. std::enable_if_t
  163. <
  164. util::is_pointlike<Geometry1>::value
  165. && util::is_box<Geometry2>::value
  166. > * = nullptr)
  167. {
  168. return strategy::within::spherical_point_box();
  169. }
  170. template <typename Geometry1, typename Geometry2>
  171. static auto within(Geometry1 const&, Geometry2 const&,
  172. std::enable_if_t
  173. <
  174. util::is_box<Geometry1>::value
  175. && util::is_box<Geometry2>::value
  176. > * = nullptr)
  177. {
  178. return strategy::within::spherical_box_box();
  179. }
  180. template <typename ComparePolicy, typename EqualsPolicy>
  181. using compare_type = typename strategy::compare::spherical
  182. <
  183. ComparePolicy,
  184. EqualsPolicy,
  185. -1
  186. >;
  187. };
  188. namespace services
  189. {
  190. template <typename Geometry1, typename Geometry2>
  191. struct default_strategy<Geometry1, Geometry2, geographic_tag, geographic_tag>
  192. {
  193. using type = strategies::relate::geographic<>;
  194. };
  195. template <typename FormulaPolicy, typename Spheroid, typename CalculationType>
  196. struct strategy_converter<strategy::disjoint::segment_box_geographic<FormulaPolicy, Spheroid, CalculationType>>
  197. {
  198. static auto get(strategy::disjoint::segment_box_geographic<FormulaPolicy, Spheroid, CalculationType> const& s)
  199. {
  200. return strategies::relate::geographic
  201. <
  202. FormulaPolicy,
  203. Spheroid,
  204. CalculationType
  205. >(s.model());
  206. }
  207. };
  208. template <typename P1, typename P2, typename FormulaPolicy, typename Spheroid, typename CalculationType>
  209. struct strategy_converter<strategy::within::geographic_winding<P1, P2, FormulaPolicy, Spheroid, CalculationType>>
  210. {
  211. static auto get(strategy::within::geographic_winding<P1, P2, FormulaPolicy, Spheroid, CalculationType> const& s)
  212. {
  213. return strategies::relate::geographic
  214. <
  215. FormulaPolicy,
  216. Spheroid,
  217. CalculationType
  218. >(s.model());
  219. }
  220. };
  221. template <typename FormulaPolicy, std::size_t SeriesOrder, typename Spheroid, typename CalculationType>
  222. struct strategy_converter<strategy::intersection::geographic_segments<FormulaPolicy, SeriesOrder, Spheroid, CalculationType>>
  223. {
  224. struct altered_strategy
  225. : strategies::relate::geographic<FormulaPolicy, Spheroid, CalculationType>
  226. {
  227. typedef strategies::relate::geographic<FormulaPolicy, Spheroid, CalculationType> base_t;
  228. explicit altered_strategy(Spheroid const& spheroid)
  229. : base_t(spheroid)
  230. {}
  231. template <typename Geometry>
  232. auto area(Geometry const&) const
  233. {
  234. return strategy::area::geographic
  235. <
  236. FormulaPolicy, SeriesOrder, Spheroid, CalculationType
  237. >(base_t::m_spheroid);
  238. }
  239. using base_t::relate;
  240. auto relate(/*...*/) const
  241. {
  242. return strategy::intersection::geographic_segments
  243. <
  244. FormulaPolicy, SeriesOrder, Spheroid, CalculationType
  245. >(base_t::m_spheroid);
  246. }
  247. template <typename ComparePolicy, typename EqualsPolicy>
  248. using compare_type = typename strategy::compare::spherical
  249. <
  250. ComparePolicy,
  251. EqualsPolicy,
  252. -1
  253. >;
  254. };
  255. static auto get(strategy::intersection::geographic_segments<FormulaPolicy, SeriesOrder, Spheroid, CalculationType> const& s)
  256. {
  257. return altered_strategy(s.model());
  258. }
  259. };
  260. template <typename FormulaPolicy, typename Spheroid, typename CalculationType>
  261. struct strategy_converter<strategy::within::geographic_point_box_by_side<FormulaPolicy, Spheroid, CalculationType>>
  262. {
  263. struct altered_strategy
  264. : strategies::relate::geographic<FormulaPolicy, Spheroid, CalculationType>
  265. {
  266. altered_strategy(Spheroid const& spheroid)
  267. : strategies::relate::geographic<FormulaPolicy, Spheroid, CalculationType>(spheroid)
  268. {}
  269. template <typename Geometry1, typename Geometry2>
  270. auto covered_by(Geometry1 const&, Geometry2 const&,
  271. std::enable_if_t
  272. <
  273. util::is_pointlike<Geometry1>::value
  274. && util::is_box<Geometry2>::value
  275. > * = nullptr) const
  276. {
  277. return strategy::covered_by::geographic_point_box_by_side
  278. <
  279. FormulaPolicy, Spheroid, CalculationType
  280. >(this->model());
  281. }
  282. template <typename Geometry1, typename Geometry2>
  283. auto within(Geometry1 const&, Geometry2 const&,
  284. std::enable_if_t
  285. <
  286. util::is_pointlike<Geometry1>::value
  287. && util::is_box<Geometry2>::value
  288. > * = nullptr) const
  289. {
  290. return strategy::within::geographic_point_box_by_side
  291. <
  292. FormulaPolicy, Spheroid, CalculationType
  293. >(this->model());
  294. }
  295. };
  296. static auto get(strategy::covered_by::geographic_point_box_by_side<FormulaPolicy, Spheroid, CalculationType> const& s)
  297. {
  298. return altered_strategy(s.model());
  299. }
  300. static auto get(strategy::within::geographic_point_box_by_side<FormulaPolicy, Spheroid, CalculationType> const& s)
  301. {
  302. return altered_strategy(s.model());
  303. }
  304. };
  305. template <typename CalculationType>
  306. struct strategy_converter<strategy::covered_by::geographic_point_box_by_side<CalculationType>>
  307. : strategy_converter<strategy::within::geographic_point_box_by_side<CalculationType>>
  308. {};
  309. } // namespace services
  310. }} // namespace strategies::relate
  311. }} // namespace boost::geometry
  312. #endif // BOOST_GEOMETRY_STRATEGIES_RELATE_GEOGRAPHIC_HPP