geos::algorithm::Centroid Class Reference

Computes the centroid of a Geometry of any dimension. More...

`#include <Centroid.h>`

## Public Member Functions

| Centroid (const geom::Geometry &geom)
| Creates a new instance for computing the centroid of a geometry.
bool | getCentroid (geom::CoordinateXY &cent) const
| Gets the computed centroid.

## Static Public Member Functions

static bool | getCentroid (const geom::Geometry &geom, geom::CoordinateXY &cent)
| Computes the centroid point of a geometry.

## Detailed Description

Computes the centroid of a Geometry of any dimension.

If the geometry is nomimally of higher dimension, but contains only components having a lower effective dimension (i.e. zero length or area), the centroid will be computed appropriately.

### Algorithm

- Dimension = 2 - Based on the usual algorithm for calculating the centroid as a weighted sum of the centroids of a decomposition of the area into (possibly overlapping) triangles. The algorithm has been extended to handle holes and multi-polygons. See http://www.faqs.org/faqs/graphics/algorithms-faq/ for further details of the basic approach.
- Dimension = 1 - Computes the average of the midpoints of all line segments weighted by the segment length.
- Dimension = 0 - Compute the average coordinate over all points.

If the input geometries are empty, a null Coordinate is returned.

## Member Function Documentation

## getCentroid() [1/2]

bool geos::algorithm::Centroid::getCentroid | ( | const geom::Geometry & | geom,
|  | geom::CoordinateXY & | cent )

static

Computes the centroid point of a geometry.

Parameters

  geom | the geometry to use
  cent | will be set to the centroid point, if any

Returns
  true if a centroid could be computed, false otherwise (empty geom)

## getCentroid() [2/2]

bool geos::algorithm::Centroid::getCentroid | ( | geom::CoordinateXY & | cent | ) | const

Gets the computed centroid.

Parameters

  cent | will be set to the centroid point, if any

Returns
  true if a centroid could be computed, false otherwise (empty geom)

The documentation for this class was generated from the following file:

- Centroid.h