返回每個Geometry對象基于二維K均值算法生成的聚類結果數量。

語法

integer  ST_ClusterKMeans(geometry winset  geom , integer  numberOfClusters);

參數

參數名稱 描述
geom 目標Geometry對象。
numberOfClusters 聚類數。

描述

  • 用于聚類的距離是幾何質心之間的距離。
  • 該函數是窗口函數。

示例

SELECT ST_ClusterKMeans(geom,2) over() ,st_AsText(geom)
    from (select unnest(ARRAY['POINT (0 0)'::geometry,
                            'POINT(1 1)'::geometry,
                            'POINT (-1 -1)'::geometry,
                            'POINT (-2 -2)'::geometry]) as geom) as test;
 st_clusterkmeans |  st_astext
------------------+--------------
                0 | POINT(0 0)
                0 | POINT(1 1)
                1 | POINT(-1 -1)
                1 | POINT(-2 -2)
(4 rows)