名前

ST_Centroid — ジオメトリの幾何学的重心を返します。

概要

geometry ST_Centroid(geometry g1);

geography ST_Centroid(geography g1, boolean use_spheroid = true);

説明

ジオメトリの幾何学的重心を計算します。[MULTI]POINTに対しては、入力座標の算術平均として計算されます。 [MULTI]LINESTRINGに対しては、各辺の重み付き長さとして計算されます。 [MULTI]POLYGONに対しては、面積から計算されます。空ジオメトリが与えられた場合には、空のGEOMETRYCOLLECTIONが返されます。NULLが与えられた場合には、NULLが返されます。CIRCULARSTRINGまたはCOMPOUNDCURVEが与えられた場合には、まずCurveToLineで直線に変換されてから、LINESTRINGと同じ計算を行います。

入力が混合次元の場合には、結果は最大次元のジオメトリの重心と同じになります (低次元ジオメトリは重心に0の「重み」を与えるためです)。

ポリゴンジオメトリに対しては、重心は必ずしもポリゴンの内部にあるわけではないことに注意して下さい。たとえば、下図のCの形のポリゴンの重心をご覧下さい。ポリゴン内部にポイントがあることを保障するにはST_PointOnSurfaceを使います。

New in 2.3.0 : CIRCULARSTRINGCOMPOUNDCURVEに対応するようになりました (CurveToLineを使います)。

Availability: 2.4.0 ジオグラフィが導入されました。

このメソッドはOGC Simple Features Implementation Specification for SQL 1.1の実装です。

このメソッドはSQL/MM仕様の実装です。 SQL-MM 3: 8.1.4, 9.5.5

Centroid of a MultiPoint.

Code
SELECT ST_Centroid(
  'MULTIPOINT (8 24,10 92,12 154,17 68,28 10,29 52,29 84,55 50,56 24,131 14,160 180,189 180)');
出力:
POINT(60.333 77.667)
Figure
Geometry figure for st-centroid-multipoint

Centroid of a LineString.

Code
SELECT ST_Centroid(
  'LINESTRING (190 160,10 190,40 90,20 70,10 10,30 40,30 10,110 40,70 10,110 10,140 40,140 10,160 30,180 10)');
出力:
POINT(76.191 79.876)
Figure
Geometry figure for visual-st-centroid-02

Centroid of a Polygon.

Code
SELECT ST_Centroid(
  'POLYGON ((190 190,10 190,10 10,190 10,190 20,160 30,60 30,60 130,190 140,190 190))');
出力:
POINT(80.251 113.405)
Figure
Geometry figure for visual-st-centroid-03

Centroid of the highest-dimension components of a GeometryCollection.

Code
SELECT ST_Centroid(
  'GEOMETRYCOLLECTION (POLYGON ((190 170,180 100,80 140,80 160,130 160,110 180,110 190,180 180,190 170)),
    LINESTRING (80 120,120 20,140 70,150 30,180 50,190 10),
    MULTIPOINT (19 150,22 49,30 13,32 101,45 35,67 88,75 16))');
出力:
POINT(143.361 148.263)
Figure
Geometry figure for visual-st-centroid-04
Code
SELECT ST_Centroid(g)
FROM  ST_GeomFromText('CIRCULARSTRING(0 2,-1 1,0 0,0.5 0,1 0,2 1,1 2,0.5 2,0 2)')  AS g ;
出力:
st_astext
-------------
 POINT(0.5 1)
(1 row)
Figure
Geometry figure for visual-st-centroid-05
Code
SELECT ST_Centroid(g)
FROM  ST_GeomFromText('COMPOUNDCURVE(CIRCULARSTRING(0 2,-1 1,0 0),(0 0,0.5 0,1 0), CIRCULARSTRING( 1 0,2 1,1 2),(1 2,0.5 2,0 2))' ) AS g;
出力:
st_astext
-------------
 POINT(0.5 1)
(1 row)
Figure
Geometry figure for visual-st-centroid-06

Centroids of the parts of a MultiPolygon.

Code
SELECT ST_Collect(ST_Centroid(geom) ORDER BY path)
FROM ST_Dump('MULTIPOLYGON (
    ((0 0,0 1,1 1,1 0,0 0)),
    ((2 2,2 3,3 3,3 2,2 2))
  )'::geometry);
出力:
MULTIPOINT((0.5 0.5),(2.5 2.5))
Figure
Geometry figure for visual-st-centroid-07