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 the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
return_centroid (with strategy)

Calculates the centroid of a geometry using the specified strategy.

Description

The free function centroid calculates the geometric center (or: center of mass) of a geometry. This version with the return_ prefix returns the centroid, and a template parameter must therefore be specified in the call.. Reasons to specify a strategy include: use another coordinate system for calculations; construct the strategy beforehand (e.g. with the radius of the Earth); select a strategy when there are more than one available for a calculation.

Synopsis

template<typename Point, typename Geometry, typename Strategy>
Point return_centroid(Geometry const & geometry, Strategy const & strategy)

Parameters

Type

Concept

Name

Description

Point

Any type fulfilling a Point Concept

-

Must be specified

Geometry const &

Any type fulfilling a Geometry Concept

geometry

A model of the specified concept

Strategy const &

Any type fulfilling a centroid Strategy Concept

strategy

The strategy which will be used for centroid calculations

Returns

The calculated centroid

Header

Either

#include <boost/geometry.hpp>

Or

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

Conformance

The function centroid implements function Centroid from the OGC Simple Feature Specification.

Behavior

Case

Behavior

Point

Returns the point itself as the centroid

Multi Point

Calculates centroid (based on average)

linear (e.g. linestring)

Calculates centroid (based on weighted length)

areal (e.g. polygon)

Calculates centroid

Empty (e.g. polygon without points)

Throws a centroid_exception

Cartesian

Implemented

Spherical

Calculates the centroid as if based on Cartesian coordinates

Supported geometries

2D

3D

Point

ok

ok

Segment

ok

ok

Box

ok

ok

Linestring

ok

nyi

Ring

ok

nyi

Polygon

ok

nyi

MultiPoint

ok

ok

MultiLinestring

ok

nyi

MultiPolygon

ok

nyi

Complexity

Linear

Available Strategies

PrevUpHomeNext