1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 // Linestring Polygon Overlay Example
13 // NOTE: this example is obsolete. Boost.Geometry can now
14 // overlay linestrings/polygons.
15 // This sample will be removed in next version.
22 #include <boost/foreach.hpp>
25 #include <boost/geometry/geometry.hpp>
26 #include <boost/geometry/geometries/linestring.hpp>
27 #include <boost/geometry/geometries/point_xy.hpp>
28 #include <boost/geometry/geometries/polygon.hpp>
29 #include <boost/geometry/geometries/adapted/c_array.hpp>
32 # include <boost/geometry/io/svg/svg_mapper.hpp>
35 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian
);
40 namespace bg
= boost::geometry
;
42 typedef bg::model::d2::point_xy
<double> point_2d
;
44 bg::model::linestring
<point_2d
> ls
;
46 const double c
[][2] = { {0, 1}, {2, 5}, {5, 3} };
47 bg::assign_points(ls
, c
);
50 bg::model::polygon
<point_2d
> p
;
52 const double c
[][2] = { {3, 0}, {0, 3}, {4, 5}, {3, 0} };
53 bg::assign_points(p
, c
);
59 std::ofstream
stream("05_b_overlay_linestring_polygon_example.svg");
60 bg::svg_mapper
<point_2d
> svg(stream
, 500, 500);
61 // Determine extend by adding geometries
65 svg
.map(ls
, "opacity:0.6;stroke:rgb(255,0,0);stroke-width:2;");
66 svg
.map(p
, "opacity:0.6;fill:rgb(0,0,255);");
69 // Calculate intersection points (turn points)
70 typedef bg::detail::segment_ratio_type
<point_2d
, bg::detail::no_rescale_policy
>::type segment_ratio
;
71 typedef bg::detail::overlay::turn_info
<point_2d
, segment_ratio
> turn_info
;
72 std::vector
<turn_info
> turns
;
73 bg::detail::get_turns::no_interrupt_policy policy
;
74 bg::detail::no_rescale_policy rescale_policy
;
75 bg::strategy::intersection::services::default_strategy
<typename
bg::cs_tag
<point_2d
>::type
>::type intersection_strategy
;
76 bg::get_turns
<false, false, bg::detail::overlay::assign_null_policy
>(ls
, p
, intersection_strategy
, rescale_policy
, turns
, policy
);
78 std::cout
<< "Intersection of linestring/polygon" << std::endl
;
79 BOOST_FOREACH(turn_info
const& turn
, turns
)
81 std::string action
= "intersecting";
82 if (turn
.operations
[0].operation
83 == bg::detail::overlay::operation_intersection
)
87 else if (turn
.operations
[0].operation
88 == bg::detail::overlay::operation_union
)
93 std::cout
<< action
<< " polygon at " << bg::dsv(turn
.point
) << std::endl
;
95 svg
.map(turn
.point
, "fill:rgb(255,128,0);stroke:rgb(0,0,100);stroke-width:1");
96 svg
.text(turn
.point
, action
, "fill:rgb(0,0,0);font-family:Arial;font-size:10px");