Centroid class

Computes the centroid of a {@link Geometry} of any dimension. If the geometry is nominally of higher dimension, but has lower effective dimension (i.e. contains only components having zero length or area), the centroid will be computed as for the equivalent lower-dimension geometry. If the input geometry is empty, a null Coordinate is returned.

Algorithm

  • Dimension 2 - the centroid is computed as the weighted sum of the centroids of a decomposition of the area into (possibly overlapping) triangles. Holes and multipolygons are handled correctly. 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. Zero-length lines are treated as points.
  • Dimension 0 - Compute the average coordinate for all points. Repeated points are all included in the average.

@version 1.7

Constructors

Centroid(Geometry geom)
Creates a new instance for computing the centroid of a geometry

Properties

areaBasePt Coordinate?
getter/setter pair
areasum2 double
getter/setter pair
cg3 Coordinate
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
lineCentSum Coordinate
getter/setter pair
ptCentSum Coordinate
getter/setter pair
ptCount int
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
totalLength double
getter/setter pair
triangleCent3 Coordinate
getter/setter pair

Methods

add(Geometry geom) → void
Adds a Geometry to the centroid total.
addHole(List<Coordinate> pts) → void
addLineSegments(List<Coordinate> pts) → void
Adds the line segments defined by an array of coordinates to the linear centroid accumulators.
addPoint(Coordinate pt) → void
Adds a point to the point centroid accumulator. @param pt a {@link Coordinate}
addPolygon(Polygon poly) → void
addShell(List<Coordinate> pts) → void
addTriangle(Coordinate p0, Coordinate p1, Coordinate p2, bool isPositiveArea) → void
getCentroid() Coordinate?
Gets the computed centroid.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setAreaBasePoint(Coordinate basePt) → void
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

area2(Coordinate p1, Coordinate p2, Coordinate p3) double
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.
centroid3(Coordinate p1, Coordinate p2, Coordinate p3, Coordinate c) → void
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.
getCentroidStatic(Geometry geom) Coordinate?
Computes the centroid point of a geometry.