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

This is an old version of boost. Click here for the latest version's documentation home page.
PrevUpHomeNext
for_each_point (const version)

Applies function f to each point.

Description

Applies a function f (functor, having operator() defined) to each point making up the geometry

Synopsis

template<typename Geometry, typename Functor>
Functor for_each_point(Geometry const & geometry, Functor f)

Parameters

Type

Concept

Name

Description

Geometry const &

Any type fulfilling a Geometry Concept

geometry

A model of the specified concept

Functor

Function or class with operator()

f

Unary function, taking a const point as argument

Header

Either

#include <boost/geometry/geometry.hpp>

Or

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

Example

Sample using for_each_point, using a function to list coordinates

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>


template <typename Point>
void list_coordinates(Point const& p)
{
    using boost::geometry::get;
    std::cout << "x = " << get<0>(p) << " y = " << get<1>(p) << std::endl;
}

int main()
{
    typedef boost::geometry::model::d2::point_xy<double> point;
    boost::geometry::model::polygon<point> poly;
    boost::geometry::read_wkt("POLYGON((0 0,0 4,4 0,0 0))", poly);
    boost::geometry::for_each_point(poly, list_coordinates<point>);
    return 0;
}

Output:

x = 0 y = 0
x = 0 y = 4
x = 4 y = 0
x = 0 y = 0

PrevUpHomeNext