// Source from the "problem with wkt io" thread // http://lists.boost.org/geometry/2013/10/2576.php #include "boost/geometry.hpp" #include "boost/geometry/geometries/geometries.hpp" #include "boost/geometry/io/wkt/wkt.hpp" using namespace boost::geometry; // define non-closed polygon type typedef model::point< double, 2, boost::geometry::cs::cartesian > Point; typedef model::polygon< Point, false, false> Polygon; void test(char const* wkt) { std::cout << "input: " << wkt << std::endl; Polygon p; read_wkt(wkt, p); std::size_t no1 = p.outer().size(); std::size_t ni1 = p.inners().empty() ? 0 : p.inners().back().size(); correct(p); std::size_t no2 = p.outer().size(); std::size_t ni2 = p.inners().empty() ? 0 : p.inners().back().size(); std::cout << "# points: " << no1 << ", " << ni1 << "; after correct: " << no2 << ", " << ni2 << std::endl; // Check if wkt impose last point to be equal to the first one. std::cout << "output: " << boost::geometry::wkt(p) << std::endl; } int main() { test("POLYGON((0.0 0.0, 10.0 0.0, 10.0 10.0, 0 10.0, 0.0 0.0))"); 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))"); return 0; }