返回給定Geometry對象的幾何中位點。

語法

geometry  ST_GeometricMedian (geometry  g , float8  tolerance , int  maxIter , boolean  failIfNotConverged);

參數

參數名稱 描述
g 目標Geometry對象。
tolerance 容差。
maxIter 最大迭代次數。
failIfNotConverged 是否在超過迭代次數后依舊沒有找到時報錯。

描述

  • 該算法將不斷迭代,直到對象之間的距離變化小于提供的公差參數為止。如果在maxIter次數之后未滿足此條件,則該函數將產生錯誤并退出,除非failIfNotConverged設置為False。
  • 如果未提供tolerance,則將基于輸入對象的范圍計算默認tolerance。
  • 如果存在點的M值,則該值將被解釋為它們的相對權重。

示例

對比ST_GeometricMedian和ST_Centroid
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)
                
12