geographic.hpp 12 KB

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