geometry STEnvelope gives a shape an axis-aligned bound. I keep the original geometry when a question asks which points actually belong inside that shape.

Separate a bound from the original region
STEnvelope returns the minimum axis-aligned bounding rectangle for an instance. That is a useful enclosing value. It can include space that the original shape doesn’t cover. A triangle makes the difference easy to see.
The example uses a triangle with corners at zero-zero, four-zero and zero-three. Its area is six square local units. The envelope extends across width four and height three. That rectangle therefore has area twelve.
A point inside the triangle must also fit inside this rectangle. The reverse statement isn’t sufficient for exact containment. The upper-right portion of the rectangle lies outside the triangle. I’d retain that distinction in a report or validation rule.
Check both kinds of interior point
The first test point has coordinates one-one. It lies inside both the triangle and its envelope. The second has coordinates three-two. It lies inside the envelope but outside the triangle.
The query returns both areas beside each test point. It also returns two containment flags. Repeating the shape measurements intentionally gives each row enough context. The label identifies why the chosen point belongs in the comparison.
All coordinates are literal geometry values using spatial reference identifier zero. The SQL contains a CTE and one SELECT. It creates no table or index and changes no session options. ORDER BY fixes the two-case presentation.
WITH ShapeInput AS
(
SELECT geometry::STGeomFromText(
'POLYGON((0 0,4 0,0 3,0 0))',0) AS Region
),
Points AS
(
SELECT Id, CAST(CaseLabel AS varchar(20)) AS CaseLabel,
geometry::Point(X,Y,0) AS TestPoint
FROM (VALUES (1,'InsideBoth',1,1),
(2,'EnvelopeOnly',3,2)) AS v(Id,CaseLabel,X,Y)
)
SELECT p.Id,p.CaseLabel,
CAST(s.Region.STArea() AS decimal(12,3)) AS ShapeArea,
CAST(s.Region.STEnvelope().STArea() AS decimal(12,3)) AS EnvelopeArea,
CAST(p.TestPoint.STX AS decimal(12,3)) AS X,
CAST(p.TestPoint.STY AS decimal(12,3)) AS Y,
s.Region.STContains(p.TestPoint) AS InsideShape,
s.Region.STEnvelope().STContains(p.TestPoint) AS InsideEnvelope
FROM ShapeInput AS s
CROSS JOIN Points AS p
ORDER BY p.Id;
Keep the exact predicate visible
The triangle’s sloping side runs from four-zero to zero-three. The point three-two sits beyond that side. Its envelope membership doesn’t move the side or fill the missing area. A bound remains a different spatial value.


STContains provides the point-membership question used here. These test points deliberately avoid either shape’s boundary. Boundary policy is a separate question from the extra area enclosed by a bound. Mixing those questions would obscure this small comparison.
I wouldn’t describe the envelope check as exact shape containment. An application can use a bounding value for a separate purpose. It still needs its intended spatial relationship when deciding membership. The query doesn’t assert an optimizer or index behavior.
Treat output representation as another choice
Both area outputs use decimal(12,3) for a stable numeric display. The underlying spatial area method returns float. Casting the display doesn’t turn all possible geometry calculations into exact decimal arithmetic. These integer-coordinate shapes keep the example narrow.
The article doesn’t depend on the envelope’s ring serialization order. Valid text descriptions can start at different corners. The measured claims concern area and point membership. Avoid treating one particular WKT spelling as the spatial identity.
The local coordinates don’t identify an Earth location. Square local units describe the area contract. Equal spatial reference identifiers alone don’t establish metres or another physical unit. Keep the coordinate system and the application’s unit meaning explicit.
Retain a counterexample when checking a bound
The one-one point confirms the ordinary included case. The three-two point prevents that success from standing in for all membership decisions. Both rows belong in the comparison. Checking only the repeated areas wouldn’t test point membership.
Compare every complete label, area and bit in both result rows. Keep the shape and envelope membership flags together. Retain the original triangle in the SQL rather than replacing it with its rectangle. The envelope-only point is the decisive counterexample.
Draw the triangle on paper once and the extra corner will stick with you.
An envelope is not the original region, it is a bound that can include additional space.
Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.
Discover more from SQL Authority with Pinal Dave
Subscribe to get the latest posts sent to your email.




