geometry.STIntersection
spatial method STIntersection (instance.STIntersection(...))
What changes
- Input
- spatial instance (and arguments)
- Output or change
- geometry
- Return type
- SQL Server return type: geometry CLR return type: SqlGeometry
Syntax at a glance
.STIntersection ( other_geometry )
Work example
Use geometry.STIntersection to return the shared part of two shapes.
Check matching SRIDs and inspect empty or collection results. Confirm both values use the same SRID before comparing or combining them.
Check your work The shared rectangle has area 8 square coordinate units.
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'POLYGON((2 0, 6 0, 6 4, 2 4, 2 0))', 0);
SELECT @left.STIntersection(@right).STAsText() AS shared_region, @left.STIntersection(@right).STArea() AS shared_area_in_square_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.