Suppose I already have a way to compute the centroids of different geometry types:
- Points (arithmetic mean of Cartesian coordinates).
- Linestrings (polylines) (weighted mean of segment mid-points in Cartesian coordinates, weighted by great-circle distance).
- Polygons (weighted mean of spherical triangle centroids converted to Cartesian coordinates, weighted by spherical triangle areas).
I've included my methods for computing each type of centroid, but they can probably be ignored.
According to the PostGIS documentation for ST_Centroid:
The centroid is equal to the centroid of the set of component Geometries of highest dimension (since the lower-dimension geometries contribute zero "weight" to the centroid).
The dimension here refers to points (0), lines (1) and polygons (2).
What is the most consistent way of defining the centroid if the geometries of highest dimension have undefined (ambiguous) centroids? There are two possibilities:
- The combined centroid is also undefined (I assume this is what ST_Centroid does).
- The combined centroid is equal to that of the geometries of highest dimension with non-zero weight. If a geometry has no defined centroid, then we give it zero weight.
An example ambiguous situation is an equally-spaced LineString going around the equator. In this case, the centre of mass is at the sphere's origin. Another situation is two hemispherical polygons, N and S, covering the whole sphere. If such ambiguous geometries are combined with a point, should the point be the centroid?
One possibility is to interpret the centroids physically: the Earth is an invisible sphere suspended by a string, such that it can rotate about its centre. The centroid is therefore the point at the southernmost point if a collection of features are present on the spherical surface and the sphere is allowed to spin until it comes to rest.
In this situation, it seems reasonable that if the sphere is covered by area polygons, then adding a single point (of infinitesimally small area) is sufficient to make it come to rest at that point.