This topic describes the ST_GeometricMedian function. This function returns the geometric median of a geometry object.
Syntax
geometry ST_GeometricMedian (geometry g , float8 tolerance , int maxIter , boolean failIfNotConverged);Parameters
| Parameter | Description |
|---|---|
| g | The geometry object that you want to specify. |
| tolerance | The tolerance that you want to specify. |
| maxIter | The maximum number of iterations. |
| failIfNotConverged | Specifies whether to report an error if this function cannot find the geometric median of the geometry object after the maximum number of iterations is reached. |
Description
- This function performs iterations until the distance change between successive iterations is less than the value of the tolerance parameter. If the distance change between successive iterations remains greater than or equal to the value of the tolerance parameter after the maximum number of iterations is reached, this function returns an error and exits unless you set the failIfNotConverged parameter to False.
- If you do not specify the tolerance parameter, this function calculates the default tolerance based on the extent of the geometry object that you specify.
- If the m coordinates of the points of the geometry object that you specify are available, the m coordinates are interpreted as the relative weights of the points.
Examples
The following example shows the difference between the ST_GeometricMedian function
and the ST_Centroid function:

SELECT ST_AsText(ST_GeometricMedian(geom)) as GeometricMedian, ST_AsText(ST_Centroid(geom)) as Centroid
from (SELECT 'MULTIPOINT((0 0), (0 1), (1 1), (2 0))'::geometry as geom) as test;
geometricmedian | centroid
--------------------------------------------+-----------------
POINT(0.665913838138866 0.666097415551148) | POINT(0.75 0.5)
(1 row)

