- 카테고리:
ST_CENTROID¶
Returns the Point representing the geometric center of a GEOGRAPHY or GEOMETRY object.
구문¶
ST_CENTROID( <geography_or_geometry_expression> )
인자¶
geography_or_geometry_expression
The argument must be an expression of type GEOGRAPHY or GEOMETRY.
반환¶
Returns a GEOGRAPHY or GEOMETRY object for the Point that represents geometric center of the input object.
사용법 노트¶
입력이 NULL인 경우, NULL을 반환합니다.
입력 오브젝트가 다양한 형식의 오브젝트(Polygon, LineString, Point)를 포함하는 GeometryCollection인 경우, ST_CENTROID는 가장 높은 차원 을 가진 형식을 사용하여 기하학적 중심을 결정합니다. 예:
GeometryCollection에 Polygon, LineString, Point가 포함된 경우, ST_CENTROID는 Polygon을 사용하고 컬렉션의 LineString 및 Point를 무시합니다.
GeometryCollection에 LineString 및 Point가 포함된 경우, ST_CENTROID는 LineString을 사용하고 컬렉션의 Point를 무시합니다.
For GEOMETRY objects, the returned GEOMETRY object has the same SRID as the input.
예¶
GEOGRAPHY Examples¶
다음 예는 LineString의 기하학적 중심을 나타내는 Point를 반환합니다.
SELECT ST_CENTROID( TO_GEOGRAPHY( 'LINESTRING(0 0, 0 -2)' ) ) as center_of_linestring; +----------------------+ | CENTER_OF_LINESTRING | |----------------------| | POINT(0 -1) | +----------------------+
다음 예는 Polygon의 기하학적 중심을 나타내는 Point를 반환합니다.
SELECT ST_CENTROID( TO_GEOGRAPHY( 'POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))' ) ) as center_of_polygon; +------------------------+ | CENTER_OF_POLYGON | |------------------------| | POINT(15 15.014819855) | +------------------------+
다음 예는 GeometryCollection의 기하학적 중심을 나타내는 Point를 반환합니다. 이 컬렉션은 Polygon, LineString, Point를 포함합니다. ST_CENTROID는 기하학적 중심을 결정할 때 Polygon만 사용합니다(LineString 및 Point는 무시함).
SELECT ST_CENTROID( TO_GEOGRAPHY( 'GEOMETRYCOLLECTION(POLYGON((10 10, 10 20, 20 20, 20 10, 10 10)), LINESTRING(0 0, 0 -2), POINT(50 -50))' ) ) as center_of_collection_with_polygons; +------------------------------------+ | CENTER_OF_COLLECTION_WITH_POLYGONS | |------------------------------------| | POINT(15 15.014819855) | +------------------------------------+
GEOMETRY Examples¶
The following example computes the centroid of a simple rectangular Polygon. Note how the result differs from the result when using ST_CENTROID with a GEOGRAPHY object
SELECT ST_CENTROID(TO_GEOMETRY('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))'));+--------------------------------------------------------------------------+ | ST_CENTROID(TO_GEOMETRY('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))')) | |--------------------------------------------------------------------------| | POINT(15 15) | +--------------------------------------------------------------------------+