...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
multi_polygon, a collection of polygons
Multi-polygon can be used to group polygons belonging to each other, e.g. Hawaii
template<typename Polygon, template< typename, typename > class Container, template< typename > class Allocator> class model::multi_polygon : public std::vector< Polygon, std::allocator< Polygon > > { // ... };
Parameter |
Default |
Description |
---|---|---|
typename Polygon |
||
template< typename, typename > class Container |
std::vector |
|
template< typename > class Allocator |
std::allocator |
Function |
Description |
Parameters |
---|---|---|
multi_polygon()
|
Default constructor, creating an empty multi_polygon. |
|
multi_polygon(std::initializer_list< Polygon > l)
|
Constructor taking std::initializer_list, filling the multi_polygon. |
std::initializer_list< Polygon >: l: |
Either
#include <boost/geometry/geometries/geometries.hpp>
Or
#include <boost/geometry/geometries/multi_polygon.hpp>
Declaration and use of the Boost.Geometry model::multi_polygon, modelling the MultiPolygon Concept
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/geometries.hpp> namespace bg = boost::geometry; int main() { typedef bg::model::point<double, 2, bg::cs::cartesian> point_t; typedef bg::model::polygon<point_t> polygon_t; typedef bg::model::multi_polygon<polygon_t> mpolygon_t; mpolygon_t mpoly1; mpolygon_t mpoly2{{{{0.0, 0.0}, {0.0, 5.0}, {5.0, 5.0}, {5.0, 0.0}, {0.0, 0.0}}, {{1.0, 1.0}, {4.0, 1.0}, {4.0, 4.0}, {1.0, 4.0}, {1.0, 1.0}}}, {{{5.0, 5.0}, {5.0, 6.0}, {6.0, 6.0}, {6.0, 5.0}, {5.0, 5.0}}}}; mpoly1.resize(2); bg::append(mpoly1[0].outer(), point_t(0.0, 0.0)); bg::append(mpoly1[0].outer(), point_t(0.0, 5.0)); bg::append(mpoly1[0].outer(), point_t(5.0, 5.0)); bg::append(mpoly1[0].outer(), point_t(5.0, 0.0)); bg::append(mpoly1[0].outer(), point_t(0.0, 0.0)); mpoly1[0].inners().resize(1); bg::append(mpoly1[0].inners()[0], point_t(1.0, 1.0)); bg::append(mpoly1[0].inners()[0], point_t(4.0, 1.0)); bg::append(mpoly1[0].inners()[0], point_t(4.0, 4.0)); bg::append(mpoly1[0].inners()[0], point_t(1.0, 4.0)); bg::append(mpoly1[0].inners()[0], point_t(1.0, 1.0)); bg::append(mpoly1[1].outer(), point_t(5.0, 5.0)); bg::append(mpoly1[1].outer(), point_t(5.0, 6.0)); bg::append(mpoly1[1].outer(), point_t(6.0, 6.0)); bg::append(mpoly1[1].outer(), point_t(6.0, 5.0)); bg::append(mpoly1[1].outer(), point_t(5.0, 5.0)); double a = bg::area(mpoly1); std::cout << a << std::endl; return 0; }
Default parameters, clockwise, closed polygon. |
|
Clockwise, closed multi_polygon. |
|
Default-construct a multi_polygon. |
|
Construct a multi_polygon containing two polygons, using C++11 unified initialization syntax. |
|
Resize a multi_polygon, store two polygons. |
|
Append point to the exterior ring of the first polygon. |
|
Resize a container of interior rings of the first polygon. |
|
Append point to the interior ring of the first polygon. |
|
Append point to the exterior ring of the second polygon. |
Output:
17