geometry.STSymDifference
spatial method STSymDifference (instance.STSymDifference(...))
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
.STSymDifference ( other_geometry )
Work example
Use geometry.STSymDifference to return parts belonging to either shape but not both.
Check matching SRIDs and inspect boundary-only contact. Confirm both values use the same SRID before comparing or combining them.
Check your work The shared middle is excluded. Remaining regions total 16 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.STSymDifference(@right).STAsText() AS non_shared_regions, @left.STSymDifference(@right).STArea() AS 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.