#include #include #include #include #include #include BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) template inline T round(T const& value, T const& factor) { return floor(0.5 + (value / factor)) * factor; } template void sample(std::string const& wkt, double factor) { typedef boost::geometry::model::polygon polygon; typedef boost::geometry::model::multi_polygon multi_polygon; multi_polygon mp; boost::geometry::read_wkt(wkt, mp); std::vector points; boost::geometry::for_each_point ( mp, [&](Point& p) { boost::geometry::set<0>(p, round(boost::geometry::get<0>(p), factor)); boost::geometry::set<1>(p, round(boost::geometry::get<1>(p), factor)); points.push_back(p); } ); std::cout << "Rounded: " << boost::geometry::wkt(mp) << std::endl; std::for_each(points.begin(), points.end(), [](Point const& p) { std::cout << boost::geometry::wkt(p) << std::endl; } ); } int main() { sample >("MULTIPOLYGON(((0 0,1.123 9.987,8.876 2.234,0 0),(3.345 4.456,7.654 8.765,9.123 5.432,3.345 4.456)))", 0.1); sample >("MULTIPOLYGON(((0 0,1.123 9.987,8.876 2.234,0 0),(3.345 4.456,7.654 8.765,9.123 5.432,3.345 4.456)))", 0.01); return 0; }