is_simple_geo.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2014-2017, Oracle and/or its affiliates.
  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_TEST_MODULE
  8. #define BOOST_TEST_MODULE test_is_simple_geo
  9. #endif
  10. #include "test_is_simple.hpp"
  11. inline bg::srs::spheroid<double> sph(double a, double rf)
  12. {
  13. double b = a - a / rf;
  14. return bg::srs::spheroid<double>(a, b);
  15. }
  16. typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > point_type;
  17. typedef bg::model::segment<point_type> segment_type;
  18. typedef bg::model::linestring<point_type> linestring_type;
  19. typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
  20. // ccw open and closed polygons
  21. typedef bg::model::polygon<point_type,false,false> open_ccw_polygon_type;
  22. typedef bg::model::polygon<point_type,false,true> closed_ccw_polygon_type;
  23. // multi-geometries
  24. typedef bg::model::multi_point<point_type> multi_point_type;
  25. typedef bg::model::multi_polygon<open_ccw_polygon_type> multi_polygon_type;
  26. // box
  27. typedef bg::model::box<point_type> box_type;
  28. BOOST_AUTO_TEST_CASE( test_is_simple_geo_multipoint )
  29. {
  30. typedef multi_point_type G;
  31. bg::strategy::intersection::geographic_segments<> s;
  32. test_simple_s(from_wkt<G>("MULTIPOINT(0 90, 0 90)"), s, false);
  33. test_simple_s(from_wkt<G>("MULTIPOINT(0 90, 1 90)"), s, false);
  34. test_simple_s(from_wkt<G>("MULTIPOINT(0 -90, 0 -90)"), s, false);
  35. test_simple_s(from_wkt<G>("MULTIPOINT(0 -90, 1 -90)"), s, false);
  36. test_simple_s(from_wkt<G>("MULTIPOINT(0 80, 1 80)"), s, true);
  37. }
  38. BOOST_AUTO_TEST_CASE( test_is_simple_geo_linestring )
  39. {
  40. typedef linestring_type G;
  41. bg::srs::spheroid<double> sph_wgs84;
  42. bg::srs::spheroid<double> sph_4053(6371228, 6371228);
  43. bg::srs::spheroid<double> sph_near_4053(6371228, 6371227);
  44. bg::strategy::intersection::geographic_segments<> s(sph_wgs84);
  45. bg::strategy::intersection::geographic_segments<> s_4053(sph_4053);
  46. bg::strategy::intersection::geographic_segments<> s_near_4053(sph_near_4053);
  47. // Two cases which in Cartesian would be a spike, but in Geographic
  48. // they go over the equator (first segment) and then over the pole
  49. // (second segment)
  50. test_simple_s(from_wkt<G>("LINESTRING(0 0, -90 0, 90 0)"), s, true);
  51. test_simple_s(from_wkt<G>("LINESTRING(0 0, 90 0, -90 0)"), s, true);
  52. // Two similar cases, but these do not go over the pole back, but
  53. // over the equator, and therefore make a spike
  54. test_simple_s(from_wkt<G>("LINESTRING(0 0, -80 0, 80 0)"), s, false);
  55. test_simple_s(from_wkt<G>("LINESTRING(0 0, 80 0, -80 0)"), s, false);
  56. // Going over the equator in a normal way, eastwards and westwards
  57. test_simple_s(from_wkt<G>("LINESTRING(-90 0, 0 0, 90 0)"), s, true);
  58. test_simple_s(from_wkt<G>("LINESTRING(90 0, 0 0, -90 0)"), s, true);
  59. test_simple_s(from_wkt<G>("LINESTRING(0 90, -90 0, 90 0)"), s, false);
  60. test_simple_s(from_wkt<G>("LINESTRING(0 90, -90 50, 90 0)"), s, false);
  61. test_simple_s(from_wkt<G>("LINESTRING(0 90, -90 -50, 90 0)"), s, true);
  62. // invalid linestrings
  63. test_simple_s(from_wkt<G>("LINESTRING(0 90, 0 90)"), s, false, false);
  64. test_simple_s(from_wkt<G>("LINESTRING(0 -90, 0 -90)"), s, false, false);
  65. test_simple_s(from_wkt<G>("LINESTRING(0 90, 1 90)"), s, false, false);
  66. test_simple_s(from_wkt<G>("LINESTRING(0 -90, 1 -90)"), s, false, false);
  67. // FAILING
  68. //test_simple_s(from_wkt<G>("LINESTRING(0 90, 0 80, 1 80, 0 90)"), s, false);
  69. //test_simple_s(from_wkt<G>("LINESTRING(0 -90, 0 -80, 1 -80, 0 -90)"), s, false);
  70. //test_simple_s(from_wkt<G>("LINESTRING(0 90, 0 80, 1 80, 1 90)"), s, false);
  71. //test_simple_s(from_wkt<G>("LINESTRING(0 -90, 0 -80, 1 -80, 1 -90)"), s, false);
  72. test_simple_s(from_wkt<G>("LINESTRING(35 0, 110 36, 159 0, 82 30)"), s, false);
  73. test_simple_s(from_wkt<G>("LINESTRING(135 0, -150 36, -101 0, -178 30)"), s, false);
  74. test_simple_s(from_wkt<G>("LINESTRING(45 0, 120 36, 169 0, 92 30)"), s, false);
  75. test_simple_s(from_wkt<G>("LINESTRING(179 0, -179 1, -179 0, 179 1)"), s, false);
  76. test_simple_s(from_wkt<G>("LINESTRING(-121 -19,37 8,-19 -15,-104 -58)"), s, false);
  77. test_simple_s(from_wkt<G>("LINESTRING(-121 -19,37 8,-19 -15,-104 -58)"), s_4053, false);
  78. test_simple_s(from_wkt<G>("LINESTRING(-121 -19,37 8,-19 -15,-104 -58)"), s_near_4053, false);
  79. // The segments are very close to each other, in WGS84 they cross,
  80. // in spherical or nearly spherical they don't cross
  81. test_simple_s(from_wkt<G>("LINESTRING(106 22,21 39,40 -12,-91 68)"), s, false);
  82. test_simple_s(from_wkt<G>("LINESTRING(106 22,21 39,40 -12,-91 68)"), s_4053, true);
  83. test_simple_s(from_wkt<G>("LINESTRING(106 22,21 39,40 -12,-91 68)"), s_near_4053, true);
  84. }
  85. BOOST_AUTO_TEST_CASE( test_is_simple_geo_multilinestring )
  86. {
  87. typedef multi_linestring_type G;
  88. bg::strategy::intersection::geographic_segments<> s_wgs84; // EPSG 4326
  89. bg::strategy::intersection::geographic_segments<> s_bessel((sph(6377397.155,299.1528128))); // EPSG 4804, 4813, 4820
  90. // FAILING
  91. //test_simple_s(from_wkt<G>("MULTILINESTRING((0 90, 0 80),(1 90, 1 80))"), s_wgs84, false);
  92. //test_simple_s(from_wkt<G>("MULTILINESTRING((0 -90, 0 -80),(1 -90, 1 -80))"), s_wgs84, false);
  93. test_simple_s(from_wkt<G>("MULTILINESTRING((35 0, 110 36),(159 0, 82 30))"), s_wgs84, false);
  94. test_simple_s(from_wkt<G>("MULTILINESTRING((135 0, -150 36),(-101 0, -178 30))"), s_wgs84, false);
  95. test_simple_s(from_wkt<G>("MULTILINESTRING((45 0, 120 36),(169 0, 92 30))"), s_wgs84, false);
  96. test_simple_s(from_wkt<G>("MULTILINESTRING((179 0, -179 1),(-179 0, 179 1))"), s_wgs84, false);
  97. test_simple_s(from_wkt<G>("MULTILINESTRING((35 2,110 36),(72 51,67 28,16 53,159 3,82 30))"), s_wgs84, false);
  98. test_simple_s(from_wkt<G>("MULTILINESTRING((35 2,110 36),(72 51,67 28,16 53,159 3,82 30))"), s_bessel, false);
  99. }