SQL Flow Field Guide

geometry::EnvelopeAggregate

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

spatial aggregate EnvelopeAggregate

What changes

Input
spatial values of each group
Output or change
one geometry/geography per group
Return type
SQL Server return type: geometry

Syntax at a glance

EnvelopeAggregate ( geometry_operand )

Work example

Use geometry.EnvelopeAggregate to compute one shared envelope around planar shapes.

Use it for bounds or candidate filtering rather than exact intersection. Keep the geometry type and SRID in the review.

Check your work The envelope is the axis-aligned 6-by-3 rectangle and can include empty space.

Practice SQL

Open in SQL Flow

Open 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, 2 0, 2 2, 0 2, 0 0))', 0) AS shape
    UNION ALL
    SELECT geometry::STGeomFromText(N'POLYGON((4 1, 6 1, 6 3, 4 3, 4 1))', 0) AS shape
)
SELECT geometry::EnvelopeAggregate(shape).STAsText() AS shared_envelope,
       geometry::EnvelopeAggregate(shape).STSrid AS result_srid,
       geometry::EnvelopeAggregate(shape).STIsValid() AS result_is_valid
FROM shapes;

Open Microsoft Learn for full syntax, permissions, and details for your version.