| Home | Libraries | People | FAQ | More

##### assign

Assigns one geometry to another geometry.

###### Description

The assign algorithm assigns one geometry, e.g. a BOX, to another geometry, e.g. a RING. This only works if it is possible and applicable.

###### Synopsis

    template<typename Geometry1, typename Geometry2>
    void assign(Geometry1 & geometry1, Geometry2 const & geometry2)

###### Parameters

Type | Concept | Name | Description
--- | --- | --- | ---
Geometry1 & | Any type fulfilling a Geometry Concept | geometry1 | A model of the specified concept (target)
Geometry2 const & | Any type fulfilling a Geometry Concept | geometry2 | A model of the specified concept (source)

###### Header

Either

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

Or

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

###### Example

Shows how to assign a geometry from another geometry

    #include <iostream>

    #include <boost/geometry.hpp>
    #include <boost/geometry/geometries/box.hpp>
    #include <boost/geometry/geometries/point_xy.hpp>
    #include <boost/geometry/geometries/polygon.hpp>
    #include <boost/geometry/geometries/adapted/boost_tuple.hpp>

    BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)

    int main()
    {
        typedef boost::geometry::model::d2::point_xy<double> point;
        typedef boost::geometry::model::box<point> box;
        typedef boost::geometry::model::polygon<point> polygon;

        point p1;
        box b;
        boost::geometry::assign_values(p1, 1, 1);
        boost::geometry::assign_values(b, 1, 1, 2, 2);

        // Assign a box to a polygon (target = source)
        polygon p;
        boost::geometry::assign(p, b);

        // Assign a point to another point type (conversion of point-type)
        boost::tuple<double, double> p2;
        boost::geometry::assign(p2, p1);

        using boost::geometry::dsv;
        std::cout
            << "box: " << dsv(b) << std::endl
            << "polygon: " << dsv(p) << std::endl
            << "point: " << dsv(p1) << std::endl
            << "point tuples: " << dsv(p2) << std::endl
            ;

        return 0;
    }

Output:

    box: ((1, 1), (2, 2))
    polygon: (((1, 1), (1, 2), (2, 2), (2, 1), (1, 1)))
    point: (1, 1)
    point tuples: (1, 1)

###### See also

- convert