Class: Centroid

jsts.algorithm.Centroid

new Centroid()

Computes the centroid of a 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
Source:

Methods

(static) getCentroid(geometry) → {jsts.geom.Coordinate}

Computes the centroid point of a geometry.
Parameters:
Name Type Description
geometry jsts.geom.Geometry the geometry to use
Source:
Returns:
the centroid point, or null if the geometry is empty
Type
jsts.geom.Coordinate

getCentroid() → {jsts.geom.Coordinate}

Gets the computed centroid.
Source:
Returns:
the computed centroid, or null if the input is empty
Type
jsts.geom.Coordinate