geometry: Static Aggregate Geometry Methods
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 grouped collections, hulls, envelopes, and unions.
Group compatible SRIDs and retain source keys when each input must remain traceable.
Check your work The aggregate dissolves the shared boundary. Result area is 24 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.
WITH shapes (shape) AS
(
SELECT geometry::STGeomFromText(N'POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))', 0) AS shape
UNION ALL
SELECT geometry::STGeomFromText(N'POLYGON((2 0, 6 0, 6 4, 2 4, 2 0))', 0) AS shape
)
SELECT geometry::UnionAggregate(shape).STAsText() AS merged_region,
geometry::UnionAggregate(shape).STSrid AS result_srid,
geometry::UnionAggregate(shape).STIsValid() AS result_is_valid
FROM shapes;
Open Microsoft Learn for full syntax, permissions, and details for your version.