• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // QuickBook Example
3 
4 // Copyright (c) 2013 Barend Gehrels, Amsterdam, the Netherlands.
5 
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)
9 
10 //[svg_mapper
11 //` Shows the usage of svg_mapper
12 
13 #include <iostream>
14 #include <fstream>
15 
16 #include <boost/geometry.hpp>
17 #include <boost/geometry/geometries/point_xy.hpp>
18 #include <boost/geometry/geometries/polygon.hpp>
19 
main()20 int main()
21 {
22     // Specify the basic type
23     typedef boost::geometry::model::d2::point_xy<double> point_type;
24 
25     // Declare some geometries and set their values
26     point_type a;
27     boost::geometry::assign_values(a, 3, 6);
28 
29     boost::geometry::model::polygon<point_type> b;
30     boost::geometry::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", b);
31 
32     boost::geometry::model::linestring<point_type> c;
33     c.push_back(point_type(3, 4));
34     c.push_back(point_type(4, 5));
35 
36     // Declare a stream and an SVG mapper
37     std::ofstream svg("my_map.svg");
38     boost::geometry::svg_mapper<point_type> mapper(svg, 400, 400);
39 
40     // Add geometries such that all these geometries fit on the map
41     mapper.add(a);
42     mapper.add(b);
43     mapper.add(c);
44 
45     // Draw the geometries on the SVG map, using a specific SVG style
46     mapper.map(a, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2", 5);
47     mapper.map(b, "fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:2");
48     mapper.map(c, "opacity:0.4;fill:none;stroke:rgb(212,0,0);stroke-width:5");
49 
50     // Destructor of map will be called - adding </svg>
51     // Destructor of stream will be called, closing the file
52 
53     return 0;
54 }
55 
56 //]
57 
58 
59 //[svg_mapper_output
60 /*`
61 Output:
62 
63 [$img/io/svg_mapper.png]
64 */
65 //]
66