ST_GeometricMedian — 返回多点的几何中值。
geometry
ST_GeometricMedian
(
geometry
geom
, float8
tolerance = NULL
, int
max_iter = 10000
, boolean
fail_if_not_converged = false
)
;
使用Weiszfeld算法计算多点几何图形的近似几何中值。几何中值是使到输入点的距离之和最小的点。它提供了一种中心性度量,与质心(质心)相比,它对异常点的敏感度较低。
算法进行迭代,直到连续迭代之间的距离变化小于提供的
tolerance
参数。如果在此之后未满足此条件
max_iterations
迭代时,该函数会产生错误并退出,除非
fail_if_not_converged
设置为
false
(默认设置)。
如果一个
tolerance
参数,则根据输入几何图形的范围计算公差值。
如果存在输入点M值,则将其解释为其相对权重。
可用性:2.3.0
增强:2.5.0增加了对M作为点数权重的支持。
This function supports 3d and will not drop the z-index.
This function supports M coordinates.
多点的几何中值(红色)和质心(绿松石)的比较。
WITH test AS (
SELECT 'MULTIPOINT((10 10), (10 40), (40 10), (190 190))'::geometry geom)
SELECT
ST_AsText(ST_Centroid(geom)) centroid,
ST_AsText(ST_GeometricMedian(geom)) median
FROM test;
centroid | median
--------------------+----------------------------------------
POINT(62.5 62.5) | POINT(25.01778421249728 25.01778421249728)
(1 row)