wkt_multi.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  6. // This file was modified by Oracle on 2014, 2015.
  7. // Modifications copyright (c) 2014-2015 Oracle and/or its affiliates.
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. //#include <iostream>
  15. #include <sstream>
  16. #include <string>
  17. #include <boost/algorithm/string.hpp>
  18. #include <boost/concept/requires.hpp>
  19. #include <boost/test/tools/floating_point_comparison.hpp>
  20. #include <boost/test/included/test_exec_monitor.hpp>
  21. #include <boost/geometry/geometries/geometries.hpp>
  22. #include <boost/geometry/io/wkt/wkt.hpp>
  23. template <typename T>
  24. void test_all();
  25. // Include the single test
  26. #define GEOMETRY_TEST_MULTI
  27. #include "io/wkt/wkt.cpp"
  28. template <typename T>
  29. void test_order_closure()
  30. {
  31. using namespace boost::geometry;
  32. typedef bg::model::point<T, 2, bg::cs::cartesian> Pt;
  33. typedef bg::model::polygon<Pt, true, true> PCWC;
  34. typedef bg::model::polygon<Pt, true, false> PCWO;
  35. typedef bg::model::polygon<Pt, false, true> PCCWC;
  36. typedef bg::model::polygon<Pt, false, false> PCCWO;
  37. typedef bg::model::multi_polygon<PCWC> MPCWC;
  38. typedef bg::model::multi_polygon<PCWO> MPCWO;
  39. typedef bg::model::multi_polygon<PCCWC> MPCCWC;
  40. typedef bg::model::multi_polygon<PCCWO> MPCCWO;
  41. std::string wkt_cwc = "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)),((0 0,0 -3,-3 -3,-3 0,0 0),(-1 -1,-2 -1,-2 -2,-1 -2,-1 -1)))";
  42. std::string wkt_cwo = "MULTIPOLYGON(((0 0,0 2,2 2,2 0)),((0 0,0 -3,-3 -3,-3 0),(-1 -1,-2 -1,-2 -2,-1 -2)))";
  43. std::string wkt_ccwc = "MULTIPOLYGON(((0 0,2 0,2 2,0 2,0 0)),((0 0,-3 0,-3 -3,0 -3,0 0),(-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))";
  44. std::string wkt_ccwo = "MULTIPOLYGON(((0 0,2 0,2 2,0 2)),((0 0,-3 0,-3 -3,0 -3),(-1 -1,-1 -2,-2 -2,-2 -1)))";
  45. test_wkt<MPCWC>(wkt_cwc, wkt_cwc, 15, 0, 12, 24);
  46. test_wkt<MPCWO>(wkt_cwc, wkt_cwc, 12, 0, 12, 24);
  47. test_wkt<MPCWO>(wkt_cwo, wkt_cwc, 12, 0, 12, 24);
  48. test_wkt<MPCCWC>(wkt_ccwc, wkt_ccwc, 15, 0, 12, 24);
  49. test_wkt<MPCCWO>(wkt_ccwc, wkt_ccwc, 12, 0, 12, 24);
  50. test_wkt<MPCCWO>(wkt_ccwo, wkt_ccwc, 12, 0, 12, 24);
  51. }
  52. template <typename T>
  53. void test_all()
  54. {
  55. using namespace boost::geometry;
  56. typedef bg::model::point<T, 2, bg::cs::cartesian> P;
  57. test_wkt<bg::model::multi_point<P> >("multipoint((1 2),(3 4))", 2);
  58. test_wkt<bg::model::multi_linestring<bg::model::linestring<P> > >("multilinestring((1 1,2 2,3 3),(4 4,5 5,6 6))", 6, 4 * sqrt(2.0));
  59. test_wkt<bg::model::multi_polygon<bg::model::polygon<P> > >("multipolygon(((0 0,0 2,2 2,2 0,0 0),(1 1,1 2,2 2,2 1,1 1)),((0 0,0 4,4 4,4 0,0 0)))", 15, 0, 21, 28);
  60. // Support for the official alternative syntax for multipoint
  61. // (provided by Aleksey Tulinov):
  62. test_relaxed_wkt<bg::model::multi_point<P> >("multipoint(1 2,3 4)", "multipoint((1 2),(3 4))");
  63. test_wrong_wkt<bg::model::multi_polygon<bg::model::polygon<P> > >(
  64. "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0),(1 1,1 2,2 2,2 1,1 1)),(0 0,0 4,4 4,4 0,0 0)))",
  65. "expected '('");
  66. test_wrong_wkt<bg::model::multi_linestring<bg::model::linestring<P> > >(
  67. "MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10)), (0 0, 1 1)",
  68. "too many tokens at ','");
  69. test_wrong_wkt<bg::model::multi_point<P> >(
  70. "MULTIPOINT((8 9), 10 11)",
  71. "expected '(' at '10'");
  72. test_wrong_wkt<bg::model::multi_point<P> >(
  73. "MULTIPOINT(12 13, (14 15))",
  74. "bad lexical cast: source type value could not be interpreted as target at '(' in 'multipoint(12 13, (14 15))'");
  75. test_wrong_wkt<bg::model::multi_point<P> >(
  76. "MULTIPOINT((16 17), (18 19)",
  77. "expected ')' in 'multipoint((16 17), (18 19)'");
  78. test_wrong_wkt<bg::model::multi_point<P> >(
  79. "MULTIPOINT(16 17), (18 19)",
  80. "too many tokens at ',' in 'multipoint(16 17), (18 19)'");
  81. test_order_closure<T>();
  82. }
  83. /*
  84. ... see comments in "wkt.cpp"
  85. union select 13,'# mpoint',npoints(geomfromtext('MULTIPOINT((1 2),(3 4))'))
  86. union select 14,'length mpoint',length(geomfromtext('MULTIPOINT((1 2),(3 4))'))
  87. union select 15,'peri mpoint',perimeter(geomfromtext('MULTIPOINT((1 2),(3 4))'))
  88. union select 16,'area mpoint',area(geomfromtext('MULTIPOINT((1 2),(3 4))'))
  89. union select 17,'# mls',npoints(geomfromtext('MULTILINESTRING((1 1,2 2,3 3),(4 4,5 5,6 6))'))
  90. union select 18,'length mls',length(geomfromtext('MULTILINESTRING((1 1,2 2,3 3),(4 4,5 5,6 6))'))
  91. union select 19,'peri mls',perimeter(geomfromtext('MULTILINESTRING((1 1,2 2,3 3),(4 4,5 5,6 6))'))
  92. union select 20,'area mls',area(geomfromtext('MULTILINESTRING((1 1,2 2,3 3),(4 4,5 5,6 6))'))
  93. union select 21,'# mpoly',npoints(geomfromtext('MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0),(1 1,1 2,2 2,2 1,1 1)),((0 0,0 4,4 4,4 0,0 0)))'))
  94. union select 22,'length mpoly',length(geomfromtext('MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0),(1 1,1 2,2 2,2 1,1 1)),((0 0,0 4,4 4,4 0,0 0)))'))
  95. union select 23,'peri mpoly',perimeter(geomfromtext('MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0),(1 1,1 2,2 2,2 1,1 1)),((0 0,0 4,4 4,4 0,0 0)))'))
  96. union select 24,'area mpoly',area(geomfromtext('MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0),(1 1,1 2,2 2,2 1,1 1)),((0 0,0 4,4 4,4 0,0 0)))'))
  97. */