Appearance
ST_WITHIN
Returns TRUE
if one GEOGRAPHY
object is within another.
A GEOGRAPHY
A is within B if and only if:
- All points of A lie inside B (either within the interior or on the boundary)
- The interiors of A and B share at least one common point
This function has the following properties:
- Reflexive: Every
GEOGRAPHY
object is within itself - Antisymmetric: If
ST_WITHIN(A, B) = TRUE
andST_WITHIN(B, A) = TRUE
, then A and B are topologically equal - Converse of
ST_CONTAINS
:ST_WITHIN(A, B)
is equivalent toST_CONTAINS(B, A)
See also:
Syntax
sql
ST_WITHIN(<a>, <b>)
Arguments
<a>
and<b>
: TheGEOGRAPHY
objects to check for the "within" relationship
Returns
Returns TRUE
if <a>
is within <b>
, otherwise returns FALSE
.
Example
sql
SELECT ST_WITHIN('POINT(1 1)'::GEOGRAPHY, 'POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'::GEOGRAPHY);
-- TRUE
SELECT ST_WITHIN('POINT(3 3)'::GEOGRAPHY, 'POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'::GEOGRAPHY);
-- FALSE