assign_points

| Home | Libraries | People | FAQ | More

##### assign_points

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/geometry.hpp>`

Or

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

###### Notes

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

###### Example

Shows usage of Boost.Geometry's assign, Boost.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/assign.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 namespace boost::assign;

        typedef boost::geometry::model::linestring<boost::tuple<int, int> > ls;

        ls line1, line2, line3;

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

        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;
    }

| tuple_list_of is part of Boost.Assign and can be used for Boost.Geometry if points are tuples
| tuple_list_of delivers a range and can therefore be used in boost::geometry::assign
| 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

- append