1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // QuickBook Example
3 
4 // Copyright (c) 2011-2012 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 //[register_linestring
11 //` Show the use of BOOST_GEOMETRY_REGISTER_LINESTRING
12 
13 #include <iostream>
14 
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/register/linestring.hpp>
18 
19 typedef boost::geometry::model::d2::point_xy<double> point_2d;
20 
BOOST_GEOMETRY_REGISTER_LINESTRING(std::vector<point_2d>)21 BOOST_GEOMETRY_REGISTER_LINESTRING(std::vector<point_2d>)
22 
23 int main()
24 {
25     // Normal usage of std::
26     std::vector<point_2d> line;
27     line.push_back(point_2d(1, 1));
28     line.push_back(point_2d(2, 2));
29     line.push_back(point_2d(3, 1));
30 
31     // Usage of Boost.Geometry's length and wkt functions
32     std::cout << "Length: "
33         << boost::geometry::length(line)
34         << std::endl;
35 
36     std::cout << "WKT: "
37         << boost::geometry::wkt(line)
38         << std::endl;
39 
40     return 0;
41 }
42 
43 //]
44 
45 
46 //[register_linestring_output
47 /*`
48 Output:
49 [pre
50 Length: 2.82843
51 WKT: LINESTRING(1 1,2 2,3 1)
52 ]
53 */
54 //]
55