Spatial constructor functions construct new spatial data types and geometries.
OceanBase Database supports the _ST_MakeEnvelope() spatial constructor function.
_ST_MakeEnvelope
_ST_MakeEnvelope() constructs a rectangle from the input coordinates of the lower-left vertex and upper-right vertex. This rectangle is often used as a bounding box for spatial queries.
The syntax is as follows:
_ST_MakeEnvelope(float xmin, float ymin, float xmax, float ymax, integer srid=unknown)
where:
float xminindicates the x coordinate (usually the longitude) of the lower-left vertex of the rectangle.float yminindicates the y coordinate (usually the latitude) of the lower-left vertex of the rectangle.float xmaxindicates the x coordinate (usually the longitude) of the upper-right vertex of the rectangle.float ymaxindicates the y coordinate (usually the latitude) of the upper-right vertex of the rectangle.integer sridindicates the spatial reference identifier (SRID), which specifies the spatial reference system (SRS) and must be a valid ID. The default valueunknownindicates that no SRS is specified.
Limitations are as follows:
- Coordinate values must be valid. To construct a valid rectangle, ensure that
xminis less thanxmax, andyminis less thanymax.
Example 1 is as follows:
obclient> SELECT ST_AsText(_ST_MakeEnvelope(10, 10, 11, 11, 4326));
In this example, a rectangle with the lower-left vertex (10, 10) and upper-right vertex (11, 11) is created.
The return result is as follows:
+-----------------------------------------------------+
| ST_AsText( _ST_MakeEnvelope(10, 10, 11, 11, 4326) ) |
+-----------------------------------------------------+
| POLYGON((10 10,11 10,11 11,10 11,10 10)) |
+-----------------------------------------------------+
1 row in set
Example 2 is as follows:
obclient> SELECT ST_ASTEXT(_ST_ClipByBox2D(ST_GEOMFROMTEXT('POLYGON((-2 -2, -2 11, 11 11, 11 -2, -2 -2))'), _ST_MakeEnvelope(0,0,10,10)));
In this example, a rectangle with the lower-left vertex (0, 0) and upper-right vertex (10, 10) is created as a bounding box for clipping. Then, _ST_ClipByBox2D() clips the polygon POLYGON((-2 -2, -2 11, 11 11, 11 -2, -2 -2)) against the rectangle.
The return result is as follows:
+--------------------------------------------------------------------------------------------------------------------------+
| ST_ASTEXT(_ST_ClipByBox2D(ST_GEOMFROMTEXT('POLYGON((-2 -2, -2 11, 11 11, 11 -2, -2 -2))'), _ST_MakeEnvelope(0,0,10,10))) |
+--------------------------------------------------------------------------------------------------------------------------+
| POLYGON((0 0,0 10,10 10,10 0,0 0)) |
+--------------------------------------------------------------------------------------------------------------------------+
1 row in set