ST_Within — Tests if a Geometry is spatially within another Geometry.
boolean ST_Within(
bytea GeomA, bytea GeomB)
;
Tests if a Geometry is spatially within another Geometry. The within predicate has the following equivalent definitions:
Every point of Geometry A is a point of Geometry B, and the interiors of the two geometries have at least one point in common.
In mathematical terms: a.Within(b) «-» (a ∩ b = a) Ʌ (I(a) ∩I(b) ≠ ᴓ)
The DE-9IM Intersection Matrix for the two geometries is T*F**F*** *
ST_Within is the inverse of ST_Contains
GeometryCollections are unsupported |
2D | 3D | M |
---|---|---|
OGC SFS for SQL. 1.1 (1999) | OGC SFS for SQL. 1.1.0 (2005) | OGC SFS for SQL. 1.2.0 (2006) | SQL-MM Part 3 |
---|---|---|---|
2.1.1.2 , 2.1.13.3 | 7.2.19.1 | 7.2.8.1 | 5.1.30 |
SELECT ST_Within(PA,PB) as AwithinB, ST_Contains(PB,PA) as BcontainsA, ST_Within(PB,PA) as BwithinA from (SELECT ST_GeomFromText('POLYGON ((3 5, 3 8, 6 8, 6 5, 3 5))') as PA, ST_GeomFromText('POLYGON ((1 1, 1 9, 8 9, 8 1, 1 1))') as PB) as foo; --Result awithinb | bcontainsa | bwithina ----------+------------+---------- t | t | f
ST_Within(A,B)=TRUE ST_Within(B,A)=FALSE |