geometry.STCentroid
spatial method STCentroid (instance.STCentroid(...))
What changes
- Input
- spatial instance (and arguments)
- Output or change
- geometry
- Return type
- SQL Server return type: geometry CLR return type: SqlGeometry Open Geospatial Consortium (OGC) type: Point
Syntax at a glance
.STCentroid ( )
Work example
Use geometry.STCentroid to calculate the center of mass of a planar shape.
Compare with the boundary because a centroid can fall outside a concave polygon. Keep the geometry type and SRID in the review.
Check your work The centroid of this symmetric square is POINT (2 2), inside the polygon.
Practice SQL
Open in SQL FlowOpen the SQL for a walkthrough. Run the example in SQL Server to check its result.
-- Planar geometry. SRID 0 coordinates here are synthetic units, not metres.
DECLARE @shape geometry;
SET @shape = geometry::STGeomFromText(N'POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))', 0);
SELECT @shape.STCentroid().STAsText() AS polygon_centroid,
@shape.STSrid AS source_srid,
@shape.STIsValid() AS source_is_valid;
Open Microsoft Learn for full syntax, permissions, and details for your version.