ST_Within queries whether a grid is contained in a geometry. It accepts geomgrid and geometry arguments and returns a boolean.
Syntax
boolean ST_Within(geomgrid grid, geometry geom);
boolean ST_Within(geometry geom, geomgrid grid);
boolean ST_Within(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. |
Description
ST_Within returns the spatial relationship between a grid and a geometry. The geometry argument must use the CGC2000 spatial reference system. Its spatial reference system identifier (SRID) must be 4490.
Examples
Example 1: Test whether a point is within a grid
The point lies outside the grid, so the function returns f.
SELECT ST_Within(
ST_geomfromtext('POINT(116.31522216796875 39.910277777777778)', 4490),
ST_gridfromtext('G001331032213300013')
); st_within
-----------
fExample 2: Test whether a smaller grid is within a larger grid
SELECT ST_Within(
ST_gridfromtext('G001331032213300013'),
ST_gridfromtext('G001331032213300')
); st_within
-----------
t