// Boost.Geometry (aka GGL, Generic Geometry Library) // QuickBook Example // Copyright (c) 2013 Barend Gehrels, Amsterdam, the Netherlands. // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) //[buffer_linestring //` Shows the buffer of a linestring #include #include #include #include #include #include #include #include #include #include #include #define HAVE_SVG #if defined(HAVE_SVG) # include # include #endif #if defined(HAVE_SVG) template void create_svg(std::string const& filename, Geometry1 const& a, Geometry2 const& b) { typedef typename boost::geometry::point_type::type point_type; std::ofstream svg(filename.c_str()); boost::geometry::svg_mapper mapper(svg, 400, 400); mapper.add(a); mapper.add(b); mapper.map(a, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2"); mapper.map(b, "fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:2"); } #endif int main() { typedef double coordinate_type; typedef boost::geometry::model::d2::point_xy point_type; typedef boost::geometry::model::polygon polygon; typedef boost::geometry::model::linestring linestring; // Declare/fill input linestring ls; boost::geometry::read_wkt("LINESTRING(0 0,4 5,7 4,10 6)", ls); // Declare strategies const double buffer_distance = 1.0; const int points_per_circle = 36; boost::geometry::strategy::buffer::distance_symmetric distance(buffer_distance); boost::geometry::strategy::buffer::join_round join(points_per_circle); // FOR NOW boost::geometry::strategy::buffer::end_round end(points_per_circle); // FOR NOW // SOON: change last two lines to : //boost::geometry::strategy::buffer::join_round join(points_per_circle); //boost::geometry::strategy::buffer::end_round end(points_per_circle); // Declare output boost::geometry::model::multi_polygon result; // Do the buffer boost::geometry::buffer_inserter(ls, std::back_inserter(result), distance, join, end); // Investigate results #ifdef HAVE_SVG create_svg("buffer_linestring.svg", ls, result); #endif return 0; } //]