全部產品
Search
文件中心

PolarDB:ST_GeometricMedian

更新時間:Jul 06, 2024

返回給定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