Package org.locationtech.jts.algorithm
Class Centroid
- java.lang.Object
-
- org.locationtech.jts.algorithm.Centroid
-
public class Centroid extends java.lang.Object
Computes the centroid of aGeometry
of any dimension. For collections the centroid is computed for the collection of non-empty elements of highest dimension. The centroid of an empty geometry isnull
.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 over all points. Repeated points are all included in the average.
- Version:
- 1.7
- See Also:
InteriorPoint
,MaximumInscribedCircle
,LargestEmptyCircle
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Coordinate
getCentroid()
Gets the computed centroid.static Coordinate
getCentroid(Geometry geom)
Computes the centroid point of a geometry.
-
-
-
Constructor Detail
-
Centroid
public Centroid(Geometry geom)
Creates a new instance for computing the centroid of a geometry
-
-
Method Detail
-
getCentroid
public static Coordinate getCentroid(Geometry geom)
Computes the centroid point of a geometry.- Parameters:
geom
- the geometry to use- Returns:
- the centroid point, or null if the geometry is empty
-
getCentroid
public Coordinate getCentroid()
Gets the computed centroid.- Returns:
- the computed centroid, or null if the input is empty
-
-