ST_CONTAINS()
All functions > GEOSPATIAL > ST_CONTAINS()
Returns TRUE if geometry/geography A fully contains geometry/geography B.
Signatures
Contains
Returns: TRUE if A contains B
ST_CONTAINS(geo1: T, geo2: T) → BOOLEAN sql
| Parameter | Type | Required | Description |
|---|---|---|---|
geo1 | T | Yes | Container geometry or geography |
geo2 | T | Yes | Contained 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:
- Returns TRUE if no points of B lie outside A, and at least one point of the interior of B lies in the interior of A
- ST_CONTAINS(A, B) is equivalent to ST_WITHIN(B, A)
- A geometry does not contain its boundary alone (use ST_COVERS for that)
- Both inputs must be the same type family (both GEOMETRY or both GEOGRAPHY)
- Returns NULL if either input is NULL
Examples
Geometry
FeatureQL
SELECT
f1 := ST_CONTAINS(ST_GEOMFROMTEXT('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'), ST_GEOMPOINT(5.0, 5.0)), -- Polygon contains interior point
f2 := ST_CONTAINS(ST_GEOMFROMTEXT('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'), ST_GEOMPOINT(15.0, 15.0)) -- Point outside polygon
;Result
| f1 BOOLEAN | f2 BOOLEAN |
|---|---|
| true | false |
Geography
FeatureQL
SELECT
f1 := ST_CONTAINS(ST_GEOGFROMTEXT('POLYGON ((2.29 48.85, 2.36 48.85, 2.36 48.87, 2.29 48.87, 2.29 48.85))'), ST_GEOGPOINT(2.33, 48.86)) -- Paris polygon contains point
;Result
| f1 BOOLEAN |
|---|
| true |
On this page