geometry.STContains
spatial predicate STContains
What changes
- Input
- one or two spatial instances
- Output or change
- bit
- Return type
- SQL Server return type: bit CLR return type: SqlBoolean
Syntax at a glance
.STContains ( other_geometry )
Work example
Use geometry.STContains to test whether one shape contains another.
Check argument direction, matching SRIDs, and boundary behavior. Confirm both values use the same SRID before comparing or combining them.
Check your work Contains returns 1 for the interior point and 0 for a boundary point. SRIDs match.
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 @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.STContains(@right) AS contains_interior_point, @left.STContains(geometry::Point(0, 2, 0)) AS contains_boundary_point,
@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.