#include #include #include #include #include #include #include #include namespace bg = boost::geometry; typedef bg::model::point point_type; typedef bg::model::polygon polygon_type; int main() { polygon_type poly, poly_copy; bg::read_wkt("POLYGON((0 0,0 10,10 10,10 0,0 0))", poly); point_type new_first; bg::read_wkt("POINT(1 1)", new_first); typedef bg::point_iterator iterator; std::cout << "initial polygon (wkt): " << bg::wkt(poly) << std::endl; std::cout << "initial polygon (dsv): " << bg::dsv(poly) << std::endl; std::cout << "first point: " << bg::wkt(*bg::points_begin(poly)) << std::endl; std::cout << "new first point: " << bg::wkt(new_first) << std::endl; *bg::points_begin(poly) = new_first; std::cout << "modified polygon(wkt): " << bg::wkt(poly) << std::endl; std::cout << "modified polygon(dsv): " << bg::dsv(poly) << std::endl; std::stringstream sstr; sstr << bg::wkt(poly); bg::read_wkt(sstr.str(), poly_copy); std::cout << "copy of modified via WKT (wkt): " << bg::wkt(poly_copy) << std::endl; std::cout << "copy of modified via WKT (dsv): " << bg::dsv(poly_copy) << std::endl; bg::correct(poly); std::cout << "trying to correct the invalid polygon" << std::endl; std::cout << "corrected polygon (wkt): " << bg::wkt(poly) << std::endl; std::cout << "corrected polygon (dsv): " << bg::dsv(poly) << std::endl; return 0; }