Tests whether a geometry or grid lies entirely within another geometry or grid.
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 geomgrid value to test. |
geom | The geometry value to test. |
Description
ST_Within returns the spatial relationship between a grid and a geometry.
The geometry argument must use the China Geodetic Coordinate System 2000 (CGC2000) spatial reference system. Set its spatial reference system identifier (SRID) to 4490.
Examples
Example 1: Check whether a point lies within a grid
SELECT ST_Within(
ST_GeomFromText('POINT(116.31522216796875 39.910277777777778)', 4490),
ST_gridfromtext('G001331032213300013')
) AS geom_in_grid;Output:
geom_in_grid
--------------
fExample 2: Check whether a finer grid lies within a coarser grid
SELECT ST_Within(
ST_gridfromtext('G001331032213300013'),
ST_gridfromtext('G001331032213300')
) AS fine_in_coarse;Output:
fine_in_coarse
----------------
tG001331032213300013 is a finer-level subdivision of G001331032213300, so it is fully contained within the coarser grid.