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

assign_points
PrevUpHomeNext

Assign a range of points to a linestring, ring or polygon.

Synopsis

template<typename Geometry, typename Range>
void assign_points(Geometry & geometry, Range const & range)

Parameters

Type

Concept

Name

Description

Geometry &

Any type fulfilling a Geometry Concept

geometry

A model of the specified concept

Range const &

Any type fulfilling a Range Concept where it range_value type fulfills the Point Concept

range

A range containg points fulfilling range and point concepts

Header

Either

#include <boost/geometry.hpp>

Or

#include <boost/geometry/algorithms/assign.hpp>

Notes
[Note] Note

Assign automatically clears the geometry before assigning (use append if you don't want that)

Example

Shows usage of Boost.Geometry's assign, and Boost.Range to assign ranges of a linestring

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>

#include <boost/geometry/geometries/adapted/boost_range/filtered.hpp>

BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)

template <typename T>
struct x_between
{
    x_between(T a, T b)
        : fa(a), fb(b)
    {}

    template <typename P>
    bool operator()(P const& p) const
    {
        return boost::geometry::get<0>(p) >= fa
            && boost::geometry::get<0>(p) <= fb;
    }
private :
    T fa, fb;
};


int main()
{
    using ls = boost::geometry::model::linestring<boost::tuple<int, int>>;

    ls line1, line2, line3;

    line1 = {{0, 0}, {2, 3}, {4, 0}, {6, 3}, {8, 0}, {10, 3}, {12, 0}};
    boost::geometry::assign_points(line2, ls({{0, 0}, {2, 2}, {4, 0}, {6, 2}, {8, 0}}));
    boost::geometry::assign_points(line3, line1 | boost::adaptors::filtered(x_between<int>(4, 8))); 1

    std::cout << "line 1: " << boost::geometry::dsv(line1) << std::endl;
    std::cout << "line 2: " << boost::geometry::dsv(line2) << std::endl;
    std::cout << "line 3: " << boost::geometry::dsv(line3) << std::endl;

    return 0;
}

1

Boost.Range adaptors can also be used in boost::geometry::assign

Output:

line 1: ((0, 0), (2, 3), (4, 0), (6, 3), (8, 0), (10, 3), (12, 0))
line 2: ((0, 0), (2, 2), (4, 0), (6, 2), (8, 0))
line 3: ((4, 0), (6, 3), (8, 0))
See also

PrevUpHomeNext