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
get

Get 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>
coordinate_type<Geometry>::type get(Geometry const & geometry)

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 const &

Any type fulfilling a Geometry Concept (usually a Point Concept)

geometry

A model of the specified concept (usually a point)

Returns

The coordinate value of specified dimension of specified geometry

Header

Either

#include <boost/geometry/geometry.hpp>

Or

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

Behavior

Case

Behavior

Point

Returns the coordinate of a point

Circle or Sphere

Returns the coordinate of the center of a circle or sphere (currently in an extension)

Spherical

Returns the coordinate of a point, in either Radian's or Degree's, depending on specified units

Complexity

Constant

Example

Get 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(1, 2);

    double x = bg::get<0>(point);
    double y = bg::get<1>(point);

    std::cout << "x=" << x << " y=" << y << std::endl;

    return 0;
}

Output:

x=1 y=2

PrevUpHomeNext