1 | // Source from the "problem with wkt io" thread
|
---|
2 | // http://lists.boost.org/geometry/2013/10/2576.php
|
---|
3 | #include "boost/geometry.hpp"
|
---|
4 | #include "boost/geometry/geometries/geometries.hpp"
|
---|
5 | #include "boost/geometry/io/wkt/wkt.hpp"
|
---|
6 |
|
---|
7 | using namespace boost::geometry;
|
---|
8 |
|
---|
9 | // define non-closed polygon type
|
---|
10 | typedef model::point< double, 2, boost::geometry::cs::cartesian > Point;
|
---|
11 | typedef model::polygon< Point, false, false> Polygon;
|
---|
12 |
|
---|
13 | void test(char const* wkt)
|
---|
14 | {
|
---|
15 | std::cout << "input: " << wkt << std::endl;
|
---|
16 | Polygon p;
|
---|
17 | read_wkt(wkt, p);
|
---|
18 |
|
---|
19 | std::size_t no1 = p.outer().size();
|
---|
20 | std::size_t ni1 = p.inners().empty() ? 0 : p.inners().back().size();
|
---|
21 | correct(p);
|
---|
22 | std::size_t no2 = p.outer().size();
|
---|
23 | std::size_t ni2 = p.inners().empty() ? 0 : p.inners().back().size();
|
---|
24 | std::cout << "# points: " << no1 << ", " << ni1 << "; after correct: "
|
---|
25 | << no2 << ", " << ni2 << std::endl;
|
---|
26 |
|
---|
27 | // Check if wkt impose last point to be equal to the first one.
|
---|
28 | std::cout << "output: " << boost::geometry::wkt(p) << std::endl;
|
---|
29 | }
|
---|
30 |
|
---|
31 | int main()
|
---|
32 | {
|
---|
33 | test("POLYGON((0.0 0.0, 10.0 0.0, 10.0 10.0, 0 10.0, 0.0 0.0))");
|
---|
34 | test("POLYGON((0.0 0.0, 10.0 0.0, 10.0 10.0, 0 10.0, 0.0 0.0), (1 1, 5 1, 5 5, 1 5, 1 1))");
|
---|
35 | return 0;
|
---|
36 | }
|
---|