A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.snowflake.com/en/sql-reference/functions/st_centroid below:

Website Navigation


ST_CENTROID | Snowflake Documentation

ST_CENTROID

Returns the Point representing the geometric center of a GEOGRAPHY or GEOMETRY object.

Syntax
ST_CENTROID( <geography_or_geometry_expression> )

Copy

Arguments
geography_or_geometry_expression

The argument must be an expression of type GEOGRAPHY or GEOMETRY.

Returns

Returns a GEOGRAPHY or GEOMETRY object for the Point that represents geometric center of the input object.

Usage notes Examples GEOGRAPHY examples

The following example returns the Point that represents the geometric center of a LineString.

SELECT ST_CENTROID(
    TO_GEOGRAPHY(
        'LINESTRING(0 0, 0 -2)'
    )
) as center_of_linestring;
+----------------------+
| CENTER_OF_LINESTRING |
|----------------------|
| POINT(0 -1)          |
+----------------------+

Copy

The following example returns the Point that represents the geometric center of a Polygon.

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) |
+------------------------+

Copy

The following example returns the Point that represents the geometric center of a GeometryCollection. This collection contains a Polygon, LineString, and Point. ST_CENTROID only uses the Polygon (and ignores the LineString and Point) when determining the geometric center.

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)             |
+------------------------------------+

Copy

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))'));

Copy

+--------------------------------------------------------------------------+
| ST_CENTROID(TO_GEOMETRY('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))')) |
|--------------------------------------------------------------------------|
| POINT(15 15)                                                             |
+--------------------------------------------------------------------------+

Copy


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4