ST_MBR function
The ST_MBR function takes a geometry as an input parameter and returns its minimum bounding rectangle.
If the given geometry is a point, then the point itself is returned. If the geometry is a horizontal linestring or a vertical linestring, the horizontal or vertical linestring itself is returned. If the given geometry is null or is empty, then null is returned.
This function can also be called as a method.
Syntax
Parameter
- geometry
- A value of type ST_Geometry or one of its subtypes that represents the geometry for which the minimum bounding rectangle is returned.
Return type
db2gse.ST_Geometry
Example
This example illustrates how the ST_MBR function can be used to return the minimum bounding rectangle of a polygon. Because the specified geometry is a polygon, the minimum bounding rectangle is returned as a polygon.
In the following
examples, the lines of results have been reformatted here for readability.
The spacing in your results will vary according to your online display.
SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_polys (id INTEGER, geometry ST_Polygon)
INSERT INTO sample_polys
VALUES (1, ST_Polygon ('polygon (( 5 5, 7 7, 5 9, 7 9, 9 11, 13 9,
15 9, 13 7, 15 5, 9 6, 5 5))', 0) )
INSERT INTO sample_polys
VALUES (2, ST_Polygon ('polygon (( 20 30, 25 35, 30 30, 20 30))', 0) )
SELECT id, CAST (ST_AsText ( ST_MBR(geometry)) AS VARCHAR(150) ) MBR
FROM sample_polys
Results:
ID MBR
--------- ----------------------------------------------------------
1 POLYGON (( 5.00000000 5.00000000, 15.00000000 5.00000000,
15.00000000 11.00000000, 5.00000000 11.00000000,
5.00000000 5.00000000))
2 POLYGON (( 20.00000000 30.00000000, 30.00000000 30.00000000,
30.00000000 35.00000000, 20.00000000 35.00000000,
20.00000000 30.00000000 ))
