Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

model::multi_linestring

multi_line, a collection of linestring

Description

Multi-linestring can be used to group lines belonging to each other, e.g. a highway (with interruptions)

Model of

MultiLineString Concept

Synopsis

template<typename LineString, template< typename, typename > class Container, template< typename > class Allocator>
class model::multi_linestring
      : public std::vector< LineString, std::allocator< LineString > >
{
  // ...
};

Template parameter(s)

Parameter

Default

Description

typename LineString

template< typename, typename > class Container

std::vector

template< typename > class Allocator

std::allocator

Constructor(s)

Function

Description

Parameters

multi_linestring()

Default constructor, creating an empty multi_linestring.

multi_linestring(std::initializer_list< LineString > l)

Constructor taking std::initializer_list, filling the multi_linestring.

std::initializer_list< LineString >: l:

Header

Either

#include <boost/geometry/geometries/geometries.hpp>

Or

#include <boost/geometry/geometries/multi_linestring.hpp>

Examples

Declaration and use of the Boost.Geometry model::multi_linestring, modelling the MultiLinestring Concept

#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>

namespace bg = boost::geometry;

int main()
{
    typedef bg::model::point<double, 2, bg::cs::cartesian> point_t;
    typedef bg::model::linestring<point_t> linestring_t;
    typedef bg::model::multi_linestring<linestring_t> mlinestring_t;

    mlinestring_t mls1; 1
    mlinestring_t mls2{{{0.0, 0.0}, {0.0, 1.0}, {2.0, 1.0}},
                       {{1.0, 0.0}, {2.0, 0.0}}}; 2

    mls1.resize(2); 3

    bg::append(mls1[0], point_t(0.0, 0.0)); 4
    bg::append(mls1[0], point_t(0.0, 1.0));
    bg::append(mls1[0], point_t(2.0, 1.0));

    bg::append(mls1[1], point_t(1.0, 0.0)); 5
    bg::append(mls1[1], point_t(2.0, 0.0));

    double l = bg::length(mls1);

    std::cout << l << std::endl;

    return 0;
}

1

Default-construct a multi_linestring.

2

Construct a multi_linestring containing two linestrings, using C++11 unified initialization syntax.

3

Resize a multi_linestring, store two linestrings.

4

Append point to the first linestring.

5

Append point to the second linestring.

Output:

4

PrevUpHomeNext