GEOS  3.9.1dev
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
geos::algorithm::Centroid Class Reference

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

#include <Centroid.h>

Collaboration diagram for geos::algorithm::Centroid:
[legend]

Public Member Functions

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

Static Public Member Functions

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

Private Member Functions

void add (const geom::Geometry &geom)
 
void setAreaBasePoint (const geom::Coordinate &basePt)
 
void add (const geom::Polygon &poly)
 
void addShell (const geom::CoordinateSequence &pts)
 
void addHole (const geom::CoordinateSequence &pts)
 
void addTriangle (const geom::Coordinate &p0, const geom::Coordinate &p1, const geom::Coordinate &p2, bool isPositiveArea)
 
void addLineSegments (const geom::CoordinateSequence &pts)
 
void addPoint (const geom::Coordinate &pt)
 

Static Private Member Functions

static void centroid3 (const geom::Coordinate &p1, const geom::Coordinate &p2, const geom::Coordinate &p3, geom::Coordinate &c)
 
static double area2 (const geom::Coordinate &p1, const geom::Coordinate &p2, const geom::Coordinate &p3)
 

Private Attributes

std::unique_ptr< geom::CoordinateareaBasePt
 
geom::Coordinate triangleCent3
 
geom::Coordinate cg3
 
geom::Coordinate lineCentSum
 
geom::Coordinate ptCentSum
 
double areasum2
 
double totalLength
 
int ptCount
 

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

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

Definition at line 61 of file Centroid.h.

Constructor & Destructor Documentation

geos::algorithm::Centroid::Centroid ( const geom::Geometry geom)
inline

Creates a new instance for computing the centroid of a geometry.

Definition at line 79 of file Centroid.h.

Member Function Documentation

void geos::algorithm::Centroid::add ( const geom::Geometry geom)
private

Adds a Geometry to the centroid total.

Parameters
geomthe geometry to add
void geos::algorithm::Centroid::add ( const geom::Polygon poly)
private
void geos::algorithm::Centroid::addHole ( const geom::CoordinateSequence pts)
private
void geos::algorithm::Centroid::addLineSegments ( const geom::CoordinateSequence pts)
private

Adds the line segments defined by an array of coordinates to the linear centroid accumulators.

Parameters
ptsan array of Coordinates
void geos::algorithm::Centroid::addPoint ( const geom::Coordinate pt)
private

Adds a point to the point centroid accumulator.

Parameters
pta Coordinate
void geos::algorithm::Centroid::addShell ( const geom::CoordinateSequence pts)
private
void geos::algorithm::Centroid::addTriangle ( const geom::Coordinate p0,
const geom::Coordinate p1,
const geom::Coordinate p2,
bool  isPositiveArea 
)
private
static double geos::algorithm::Centroid::area2 ( const geom::Coordinate p1,
const geom::Coordinate p2,
const geom::Coordinate p3 
)
staticprivate

Returns twice the signed area of the triangle p1-p2-p3. The area is positive if the triangle is oriented CCW, and negative if CW.

static void geos::algorithm::Centroid::centroid3 ( const geom::Coordinate p1,
const geom::Coordinate p2,
const geom::Coordinate p3,
geom::Coordinate c 
)
staticprivate

Computes three times the centroid of the triangle p1-p2-p3. The factor of 3 is left in to permit division to be avoided until later.

static bool geos::algorithm::Centroid::getCentroid ( const geom::Geometry geom,
geom::Coordinate cent 
)
static

Computes the centroid point of a geometry.

Parameters
geomthe geometry to use
centwill be set to the centroid point, if any
Returns
true if a centroid could be computed, false otherwise (empty geom)
bool geos::algorithm::Centroid::getCentroid ( geom::Coordinate cent) const

Gets the computed centroid.

Parameters
centwill be set to the centroid point, if any
Returns
true if a centroid could be computed, false otherwise (empty geom)
void geos::algorithm::Centroid::setAreaBasePoint ( const geom::Coordinate basePt)
private

Member Data Documentation

std::unique_ptr<geom::Coordinate> geos::algorithm::Centroid::areaBasePt
private

Definition at line 100 of file Centroid.h.

double geos::algorithm::Centroid::areasum2
private

Definition at line 105 of file Centroid.h.

geom::Coordinate geos::algorithm::Centroid::cg3
private

Definition at line 102 of file Centroid.h.

geom::Coordinate geos::algorithm::Centroid::lineCentSum
private

Definition at line 103 of file Centroid.h.

geom::Coordinate geos::algorithm::Centroid::ptCentSum
private

Definition at line 104 of file Centroid.h.

int geos::algorithm::Centroid::ptCount
private

Definition at line 107 of file Centroid.h.

double geos::algorithm::Centroid::totalLength
private

Definition at line 106 of file Centroid.h.

geom::Coordinate geos::algorithm::Centroid::triangleCent3
private

Definition at line 101 of file Centroid.h.


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