• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //[make_with_range
11 //` Using make to construct a linestring with two different range types
12 
13 #include <iostream>
14 
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/geometries/linestring.hpp>
17 #include <boost/geometry/geometries/point_xy.hpp>
18 #include <boost/geometry/geometries/adapted/c_array.hpp>
19 
BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)20 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) /*< Necessary to register a C array like {1,2} as a point >*/
21 
22 int main()
23 {
24     using boost::geometry::make;
25     using boost::geometry::detail::make::make_points;
26 
27     typedef boost::geometry::model::d2::point_xy<double> point;
28     typedef boost::geometry::model::linestring<point> linestring;
29 
30     double coordinates[][2] = {{1,2}, {3,4}, {5, 6}}; /*< Initialize with C array points >*/
31     linestring ls = make_points<linestring>(coordinates);
32     std::cout << boost::geometry::dsv(ls) << std::endl;
33 
34     point points[3] = { make<point>(9,8), make<point>(7,6), make<point>(5,4) }; /*< Construct array with points, using make which should work for any point type >*/
35     std::cout << boost::geometry::dsv(make_points<linestring>(points)) << std::endl; /*< Construct linestring with point-array and output it as Delimiter Separated Values >*/
36 
37     return 0;
38 }
39 
40 //]
41 
42 
43 //[make_with_range_output
44 /*`
45 Output:
46 [pre
47 ((1, 2), (3, 4), (5, 6))
48 ((9, 8), (7, 6), (5, 4))
49 ]
50 */
51 //]
52