geography.STDifference
spatial method STDifference (instance.STDifference(...))
What changes
- Input
- spatial instance (and arguments)
- Output or change
- geography
- Return type
- SQL Server return type: geography CLR return type: SqlGeography
Syntax at a glance
.STDifference ( other_geography )
Work example
Use geography.STDifference to subtract the shared portion of another shape.
Check matching SRIDs and inspect empty, split, or collection results. Confirm both values use the same SRID before comparing or combining them.
Check your work The result keeps the part of the first polygon outside the second; both inputs share SRID 4326.
Practice SQL
Open in SQL FlowOpen the SQL for a walkthrough. Run the example in SQL Server to check its result.
SELECT a.shape.STDifference(b.shape).STGeometryType() AS remaining_type, a.shape.STDifference(b.shape).STArea() AS remaining_area_m2 FROM (VALUES (geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326))) AS a(shape) CROSS JOIN (VALUES (geography::STGeomFromText('POLYGON((-122.351 47.656, -122.341 47.656, -122.341 47.661, -122.351 47.661, -122.351 47.656))', 4326))) AS b(shape);
Open Microsoft Learn for full syntax, permissions, and details for your version.