返回給定Geometry對象或Geography對象的形心。
語法
geometry ST_Centroid(geometry g1);
geography ST_Centroid(geography g1 , boolean useSpheroid);
參數
參數名稱 | 描述 |
---|---|
g1 | 目標Geometry對象或Geography對象。 |
useSpheroid | 對于Geography對象,是否使用橢球模式。默認為True。 |
描述
- MULTIPOINT的形心:
SELECT ST_AsText(ST_Centroid('MULTIPOINT(1 1,-1 -1)'::geometry)); st_astext ------------ POINT(0 0) (1 row)
- LINESTRING的形心:
SELECT ST_AsText(ST_Centroid('LINESTRING(0 0,0 1,1 2)'::geometry)); st_astext ------------------------------------------- POINT(0.292893218813453 1.08578643762691) (1 row)