This topic describes the ST_Within function. This function checks whether a geometry object is included in another geometry object.
Syntax
boolean ST_Within(geometry A , geometry B);
Parameters
Parameter | Description |
---|---|
A | The first geometry object that you want to specify. The first geometry object is referred to as Geometry Object A. |
B | The second geometry object that you want to specify. The second geometry object is referred to as Geometry Object B. |
Description
- The two geometry objects that you specify in this function must use the same projection method and must have the same spatial reference identifier (SRID).
- If both ST_Within(A,B) and ST_Within(B,A) return True, Geometry Object A and Geometry B are spatially equal.
- This function does not support GeometryCollection objects.
- You cannot specify invalid geometry objects for this function. If you specify invalid geometry objects, this function returns an incorrect result.
- This function generates a bounding box, which allows you to use the indexes that are available on the geometry objects that you specify. If you do not want to use the indexes, we recommend that you use the _ST_Within function.
Examples
SELECT ST_Within('POLYGON((1 1,1 2,2 2,2 1,1 1))'::geometry,'POLYGON((0 0,0 3,3 3,3 0,0 0))'::geometry);
st_within
-----------
t
(1 row)