set

| Home | Libraries | People | FAQ | More

##### set

Set coordinate value of a geometry (usually a point)

###### Description

The free functions get and set are two of the most important functions of Boost.Geometry, both within the library, as also for the library user. With these two functions you normally get and set coordinate values from and for a point, box, segment or sphere.

###### Synopsis

    template<std::size_t Dimension, typename Geometry>
    void set(Geometry & geometry, typename coordinate_type< Geometry >::type const & value)

###### Parameters

Type | Concept | Name | Description
--- | --- | --- | ---
Dimension | Dimension, this template parameter is required. Should contain [0 .. n-1] for an n-dimensional geometry | - | Must be specified
Geometry & | Any type fulfilling a Geometry Concept (usually a Point Concept) | geometry | A model of the specified concept (usually a point)
typename coordinate_type< Geometry >::type const & |  | value | The coordinate value to set

###### Header

Either

`#include <boost/geometry.hpp>`

Or

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

| Note
If you host both the std:: library namespace and boost::geometry:: namespace set might become ambiguous, std::set is a collection. So don't do that or refer to geometry::set then explicitly.

###### Behavior

Case | Behavior
--- | ---
Point | Sets the coordinate of a point
Circle or Sphere | Sets the coordinate of the center of a circle or sphere (currently in an extension)
Spherical | Sets the coordinate of a point, in either Radian's or Degree's, depending on specified units

###### Complexity

Constant

###### Example

Set the coordinate of a point

    #include <iostream>

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

    namespace bg = boost::geometry;

    int main()
    {
        bg::model::d2::point_xy<double> point;

        bg::set<0>(point, 1);
        bg::set<1>(point, 2);

        std::cout << "Location: " << bg::dsv(point) << std::endl;

        return 0;
    }

Output:

    Location: (1, 2)