SQL Flow Field Guide

geometry: OGC Methods on Geometry Instances

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

none (documentation, rules or examples)

What changes

Input
none
Output or change
none

Syntax at a glance

n/a (reference page)

Work example

Use geometry methods for standard shape measurements, predicates, and conversions.

Choose a method from its result and test boundaries with a matching SRID.

Check your work The square area is 16 square coordinate units and it contains the point, so distance is 0.

Practice SQL

Open in SQL Flow

Open 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 @left geometry;
DECLARE @right geometry;
SET @left = geometry::STGeomFromText(N'POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))', 0);
SET @right = geometry::STGeomFromText(N'POINT(2 2)', 0);
SELECT @left.STArea() AS area_in_square_coordinate_units, @left.STContains(@right) AS contains_point, @left.STDistance(@right) AS distance_in_coordinate_units,
       @left.STSrid AS left_srid,
       @right.STSrid AS right_srid,
       @left.STIsValid() AS left_is_valid,
       @right.STIsValid() AS right_is_valid;

Open Microsoft Learn for full syntax, permissions, and details for your version.