Spatial constructors are functions used to create new spatial data types and geometric shapes.
The OceanBase AI Database currently supports the spatial constructor _ST_MakeEnvelope.
_ST_MakeEnvelope
The _ST_MakeEnvelope function constructs a rectangle given its lower-left and upper-right coordinates. This rectangle is commonly used as the bounding box for spatial queries.
The syntax is as follows:
_ST_MakeEnvelope(float xmin, float ymin, float xmax, float ymax, integer srid=unknown)
Parameter description:
float xmin: the x-coordinate (usually longitude) of the lower-left corner of the rectangle.float ymin: The y-coordinate of the lower-left corner of the rectangle, typically representing latitude.float xmax: The x-coordinate of the upper-right corner of the rectangle, typically the longitude.float ymax: The y-coordinate of the upper-right corner of the rectangle, typically representing latitude.integer srid: The identifier of the spatial reference system. It is a valid identifier used to specify the spatial reference system for coordinates. The default valueunknownindicates that no spatial reference system is specified.
Limitations:
- The coordinate values must be valid.
xminmust be less thanxmax, andyminmust be less thanymaxto form a valid rectangle.
Example 1 is as follows:
obclient> SELECT ST_AsText(_ST_MakeEnvelope(10, 10, 11, 11, 4326));
In this example, a rectangle is created with its lower-left corner at (10, 10) and its upper-right corner at (11, 11).
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 corner at (0, 0) and the upper-right corner at (10, 10) is first created as the clipping region. Then, the _ST_ClipByBox2D function is used to clip the original 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