geographic.hpp 12 KB

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