ST_WITHIN()
All functions > GEOSPATIAL > ST_WITHIN()
Returns TRUE if geometry/geography A is fully within geometry/geography B.
Signatures
Within
Returns: TRUE if A is within B
ST_WITHIN(geo1: T, geo2: T) → BOOLEAN sql
| Parameter | Type | Required | Description |
|---|---|---|---|
geo1 | T | Yes | Geometry or geography to test |
geo2 | T | Yes | Container geometry or geography |
With:
T: Custom types: GEOM_POINT | GEOM_LINESTRING | GEOM_POLYGON | GEOM_MULTIPOINT | GEOM_MULTILINESTRING | GEOM_MULTIPOLYGON | GEOM_MULTIANY | GEOG_POINT | GEOG_LINESTRING | GEOG_POLYGON | GEOG_MULTIPOINT | GEOG_MULTILINESTRING | GEOG_MULTIPOLYGON | GEOG_MULTIANY
Signature notes:
- ST_WITHIN(A, B) is equivalent to ST_CONTAINS(B, A)
- Both inputs must be the same type family
- Returns NULL if either input is NULL
Examples
Geometry
FeatureQL
SELECT
f1 := ST_WITHIN(ST_GEOMPOINT(5.0, 5.0), ST_GEOMFROMTEXT('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')), -- Point within polygon
f2 := ST_WITHIN(ST_GEOMPOINT(15.0, 15.0), ST_GEOMFROMTEXT('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) -- Point outside polygon
;Result
| f1 BOOLEAN | f2 BOOLEAN |
|---|---|
| true | false |
Geography
FeatureQL
SELECT
f1 := ST_WITHIN(ST_GEOGPOINT(2.33, 48.86), ST_GEOGFROMTEXT('POLYGON ((2.29 48.85, 2.36 48.85, 2.36 48.87, 2.29 48.87, 2.29 48.85))')) -- Point within Paris polygon
;Result
| f1 BOOLEAN |
|---|
| true |
On this page