Add WKT support for Multipolygon_with_holes

This commit is contained in:
Andreas Fabri 2023-07-20 10:51:51 +01:00
parent 24ca8b4eb4
commit 879b7ea139
3 changed files with 28 additions and 2 deletions

View File

@ -4,7 +4,6 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_repair_2/Polygon_repair_2.h> #include <CGAL/Polygon_repair_2/Polygon_repair_2.h>
#include <CGAL/Polygon_repair_2/draw_multipolygon_with_holes_2.h> #include <CGAL/Polygon_repair_2/draw_multipolygon_with_holes_2.h>
// #include <CGAL/IO/WKT.h> // #include <CGAL/IO/WKT.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;

View File

@ -1,5 +1,6 @@
#include <CGAL/Exact_predicates_exact_constructions_kernel.h> #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/IO/WKT.h> #include <CGAL/IO/WKT.h>
#include <CGAL/Polygon_repair_2/Multipolygon_with_holes_2.h>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
@ -11,7 +12,7 @@ int main(int argc, char* argv[])
{ {
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon; typedef CGAL::Polygon_with_holes_2<Kernel> Polygon;
typedef std::deque<Polygon> MultiPolygon; typedef std::deque<Polygon> MultiPolygon;
typedef CGAL::Multipolygon_with_holes_2<Kernel> Multipolygon_with_holes_2;
{ {
std::ifstream is((argc>1)?argv[1]:"data/polygons.wkt"); std::ifstream is((argc>1)?argv[1]:"data/polygons.wkt");
std::list<Polygon> polys; std::list<Polygon> polys;
@ -33,5 +34,14 @@ int main(int argc, char* argv[])
for(Polygon p : mp) for(Polygon p : mp)
std::cout<<p<<std::endl; std::cout<<p<<std::endl;
} }
{
std::ifstream is((argc>2)?argv[2]:"data/multipolygon.wkt");
Multipolygon_with_holes_2 mp;
CGAL::IO::read_multi_polygon_WKT(is, mp);
std::cout << mp << std::endl;
CGAL::IO::write_multi_polygon_WKT(std::cout, mp);
std::cout << std::endl;
}
return 0; return 0;
} }

View File

@ -19,6 +19,7 @@
#include <CGAL/Point_3.h> #include <CGAL/Point_3.h>
#include <CGAL/Polygon_2.h> #include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h> #include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Polygon_repair_2/Multipolygon_with_holes_2.h>
#include <CGAL/IO/WKT/traits_point.h> #include <CGAL/IO/WKT/traits_point.h>
#include <CGAL/IO/WKT/traits_point_3.h> #include <CGAL/IO/WKT/traits_point_3.h>
@ -345,6 +346,22 @@ bool read_multi_polygon_WKT(std::istream& in,
return !in.fail(); return !in.fail();
} }
template<typename Kernel, typename Container>
bool read_multi_polygon_WKT(std::istream& in,
Multipolygon_with_holes_2<Kernel,Container>& mp)
{
return read_multi_polygon_WKT(in, mp.polygons());
}
template<typename Kernel, typename Container>
std::ostream& write_multi_polygon_WKT(std::ostream& out,
Multipolygon_with_holes_2<Kernel,Container>& mp)
{
return write_multi_polygon_WKT(out, mp.polygons());
}
//! \ingroup PkgStreamSupportIoFuncsWKT //! \ingroup PkgStreamSupportIoFuncsWKT
//! //!
//! \brief writes `point` into a WKT stream. //! \brief writes `point` into a WKT stream.