1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2013, 2014 Barend Gehrels, Amsterdam, the Netherlands.
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 //[buffer_with_strategies
11 //` Shows how the buffer algorithm can be used to create a buffer of a linestring, a multi point, a multi polygon
13 #include <boost/geometry.hpp>
14 #include <boost/geometry/geometries/point_xy.hpp>
15 #include <boost/geometry/geometries/geometries.hpp>
16 /*<-*/ #include "../examples_utils/create_svg_buffer.hpp" /*->*/
20 typedef double coordinate_type
;
21 typedef boost::geometry::model::d2::point_xy
<coordinate_type
> point
;
22 typedef boost::geometry::model::polygon
<point
> polygon
;
25 const double buffer_distance
= 1.0;
26 const int points_per_circle
= 36;
27 boost::geometry::strategy::buffer::distance_symmetric
<coordinate_type
> distance_strategy(buffer_distance
);
28 boost::geometry::strategy::buffer::join_round
join_strategy(points_per_circle
);
29 boost::geometry::strategy::buffer::end_round
end_strategy(points_per_circle
);
30 boost::geometry::strategy::buffer::point_circle
circle_strategy(points_per_circle
);
31 boost::geometry::strategy::buffer::side_straight side_strategy
;
34 boost::geometry::model::multi_polygon
<polygon
> result
;
36 // Declare/fill a linestring
37 boost::geometry::model::linestring
<point
> ls
;
38 boost::geometry::read_wkt("LINESTRING(0 0,4 5,7 4,10 6)", ls
);
40 // Create the buffer of a linestring
41 boost::geometry::buffer(ls
, result
,
42 distance_strategy
, side_strategy
,
43 join_strategy
, end_strategy
, circle_strategy
);
44 /*<-*/ create_svg_buffer("buffer_linestring.svg", ls
, result
); /*->*/
46 // Declare/fill a multi point
47 boost::geometry::model::multi_point
<point
> mp
;
48 boost::geometry::read_wkt("MULTIPOINT((3 3),(4 4),(6 2))", mp
);
50 // Create the buffer of a multi point
51 boost::geometry::buffer(mp
, result
,
52 distance_strategy
, side_strategy
,
53 join_strategy
, end_strategy
, circle_strategy
);
54 /*<-*/ create_svg_buffer("buffer_multi_point.svg", mp
, result
); /*->*/
56 // Declare/fill a multi_polygon
57 boost::geometry::model::multi_polygon
<polygon
> mpol
;
58 boost::geometry::read_wkt("MULTIPOLYGON(((0 1,2 5,5 3,0 1)),((1 1,5 2,5 0,1 1)))", mpol
);
60 // Create the buffer of a multi polygon
61 boost::geometry::buffer(mpol
, result
,
62 distance_strategy
, side_strategy
,
63 join_strategy
, end_strategy
, circle_strategy
);
64 /*<-*/ create_svg_buffer("buffer_multi_polygon.svg", mpol
, result
); /*->*/