1 // Boost.Geometry
2 // QuickBook Example
3
4 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2015 Adam Wulkiewicz, Lodz, Poland.
6
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)
10
11 //[multi_linestring
12 //` Declaration and use of the Boost.Geometry model::multi_linestring, modelling the MultiLinestring Concept
13
14 #include <iostream>
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/geometries/geometries.hpp>
17
18 namespace bg = boost::geometry;
19
main()20 int main()
21 {
22 typedef bg::model::point<double, 2, bg::cs::cartesian> point_t;
23 typedef bg::model::linestring<point_t> linestring_t;
24 typedef bg::model::multi_linestring<linestring_t> mlinestring_t;
25
26 mlinestring_t mls1; /*< Default-construct a multi_linestring. >*/
27
28 #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) \
29 && !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
30
31 mlinestring_t mls2{{{0.0, 0.0}, {0.0, 1.0}, {2.0, 1.0}},
32 {{1.0, 0.0}, {2.0, 0.0}}}; /*< Construct a multi_linestring containing two linestrings, using C++11 unified initialization syntax. >*/
33
34 #endif
35
36 mls1.resize(2); /*< Resize a multi_linestring, store two linestrings. >*/
37
38 bg::append(mls1[0], point_t(0.0, 0.0)); /*< Append point to the first linestring. >*/
39 bg::append(mls1[0], point_t(0.0, 1.0));
40 bg::append(mls1[0], point_t(2.0, 1.0));
41
42 bg::append(mls1[1], point_t(1.0, 0.0)); /*< Append point to the second linestring. >*/
43 bg::append(mls1[1], point_t(2.0, 0.0));
44
45 double l = bg::length(mls1);
46
47 std::cout << l << std::endl;
48
49 return 0;
50 }
51
52 //]
53
54
55 //[multi_linestring_output
56 /*`
57 Output:
58 [pre
59 4
60 ]
61 */
62 //]
63