is_valid_geo.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
  4. // Copyright (c) 2014-2018, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  6. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  7. // Licensed under the Boost Software License version 1.0.
  8. // http://www.boost.org/users/license.html
  9. #ifndef BOOST_TEST_MODULE
  10. #define BOOST_TEST_MODULE test_is_valid_geo
  11. #endif
  12. #include <limits>
  13. #include <iostream>
  14. #include <boost/test/included/unit_test.hpp>
  15. #include "test_is_valid.hpp"
  16. #include <boost/geometry/core/coordinate_type.hpp>
  17. #include <boost/geometry/algorithms/correct.hpp>
  18. #include <boost/geometry/algorithms/intersection.hpp>
  19. #include <boost/geometry/algorithms/reverse.hpp>
  20. BOOST_AUTO_TEST_CASE( test_is_valid_geo_polygon )
  21. {
  22. typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > pt;
  23. typedef bg::model::polygon<pt, false> G;
  24. typedef validity_tester_geo_areal<false> tester;
  25. typedef test_valid<tester, G> test;
  26. test::apply("p01", "POLYGON((-1 -1, 1 -1, 1 1, -1 1, -1 -1),(-0.5 -0.5, -0.5 0.5, 0.0 0.0, -0.5 -0.5),(0.0 0.0, 0.5 0.5, 0.5 -0.5, 0.0 0.0))", true);
  27. }
  28. template <typename Poly, typename Spheroid>
  29. void test_valid_s(std::string const& wkt,
  30. Spheroid const& sph,
  31. bool expected_result)
  32. {
  33. bg::strategy::intersection::geographic_segments<> is(sph);
  34. bg::strategy::area::geographic<> as(sph);
  35. Poly p;
  36. bg::read_wkt(wkt, p);
  37. bg::correct(p, as);
  38. BOOST_CHECK(bg::is_valid(p, is) == expected_result);
  39. }
  40. BOOST_AUTO_TEST_CASE( test_is_valid_epsg4053_polygon )
  41. {
  42. typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > pt;
  43. typedef bg::model::polygon<pt, false> po;
  44. bg::srs::spheroid<double> epsg4053(6371228, 6371228);
  45. bg::srs::spheroid<double> wgs84;
  46. // NOTE: the orientation is different in these CSes,
  47. // in one of them the polygon is corrected before passing it into is_valid()
  48. test_valid_s<po>("POLYGON((-148 -68,178 -74,76 0,-148 -68))", wgs84, true);
  49. test_valid_s<po>("POLYGON((-148 -68,178 -74,76 0,-148 -68))", epsg4053, true);
  50. test_valid_s<po>("POLYGON((-152 -54,-56 43,142 -52,-152 -54))", wgs84, true);
  51. test_valid_s<po>("POLYGON((-152 -54,-56 43,142 -52,-152 -54))", epsg4053, true);
  52. return;
  53. }