Export (0) Print
Expand All
Expand Minimize

STCentroid (geometry Data Type)

Returns the geometric center of a geometry instance that consists of one or more polygons.

Applies to: SQL Server (SQL Server 2012 through current version), Azure SQL Database.

.STCentroid ( )

SQL Server return type: geometry

CLR return type: SqlGeometry

Open Geospatial Consortium (OGC) type: Point

STCentroid() returns null if the geometry instance is not a Polygon, CurvePolygon, or MultiPolygon type.

A. Computing the centroid of a Polygon instance

The following example uses STCentroid() to compute the centroid of a polygon geometry instance:

DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POLYGON((0 0, 3 0, 3 3, 0 3, 0 0),(2 2, 2 1, 1 1, 1 2, 2 2))', 0);
SELECT @g.STCentroid().ToString();

B. Computing the centroid of a CurvePolygon instance

The following example computes the centroid for a CurvePolygon instance:

DECLARE @g geometry = 'CURVEPOLYGON(CIRCULARSTRING(0 4, 4 0, 8 4, 4 8, 0 4), CIRCULARSTRING(2 4, 4 2, 6 4, 4 6, 2 4))';

SELECT @g.STCentroid().ToString() AS Centroid

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft