ST_Contains returns true if the first argument spatially contains the second. Containment holds when all points of the second argument lie within the interior or boundary of the first, and the two interiors share at least one point.
Syntax
boolean ST_Contains(geomgrid grid, geometry geom);
boolean ST_Contains(geometry geom, geomgrid grid);
boolean ST_Contains(geomgrid grid1, geomgrid grid2);Parameters
| Parameter | Description |
|---|---|
grid | The grid whose spatial relationship you want to query. |
geom | The geometry whose spatial relationship you want to query. |
grid1 | The geomgrid value to test as the container (grid-vs-grid overload). |
grid2 | The geomgrid value to test as the contained object (grid-vs-grid overload). |
Examples
Example 1: Grid does not contain the point
The grid G001331032213300013 is a fine-grained cell. The POINT at approximately (116.315, 39.910) falls outside it, so the function returns f.
SELECT ST_Contains(
ST_GridFromText('G001331032213300013'),
ST_GeomFromText('POINT(116.31522216796875 39.910277777777778)', 4490)
); st_contains
-------------
fExample 2: Parent grid contains a child grid
The shorter grid code G00133103221330 represents a coarser cell that fully contains G001331032213300013, so the function returns t.
SELECT ST_Contains(
ST_GridFromText('G00133103221330'),
ST_GridFromText('G001331032213300013')
); st_contains
-------------
t