ST_BuildMBRAggr and ST_GetAggrResult functions
Use the ST_BuildMBRAggr and ST_GetAggrResult functions combined to aggregate a set of geometries from a column into a single geometry. The combination constructs a rectangle that represents the minimum bounding rectangle that encloses all the geometries in the column. Z and M coordinates are discarded when the aggregate is computed.
db2gse.ST_Get_AggrResult(MAX(db2gse.ST_BuildMBRAggr(columnName)))
If all of the geometries to be combined are null, then null is returned. If all of the geometries are either null or empty, then an empty geometry is returned. If the minimum bounding rectangle of all the geometries to be combined results in a point, then this point is returned as an ST_Point value. If the minimum bounding rectangle of all the geometries to be combined results in a horizontal or vertical linestring, then this linestring is returned as an ST_LineString value. Otherwise, the minimum bounding rectangle is returned as an ST_Polygon value.
Syntax
Parameter
- geometries
- A selected column that has a type of ST_Geometry or one of its subtypes and represents all the geometries for which the minimum bounding rectangle is to be computed.
Return type
db2gse.ST_Geometry
Restrictions
- In a partitioned database environment
- If GROUP BY clause is used in the full-select.
- If you use a function other than the Db2® aggregate function MAX.
Example
In the following example, the lines of results have been reformatted 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_points (id integer, geometry ST_Point)
INSERT INTO sample_points (id, geometry)
VALUES
(1, ST_Point(2, 3, 1)),
(2, ST_Point(4, 5, 1)),
(3, ST_Point(13, 15, 1)),
(4, ST_Point(12, 5, 1)),
(5, ST_Point(23, 2, 1)),
(6, ST_Point(11, 4, 1))
SELECT cast(ST_GetAggrResult(MAX(ST_BuildMBRAggr
(geometry)))..ST_AsText AS varchar(160))
AS ";Aggregate_of_Points";
FROM sample_points
Aggregate_of_Points
----------------------------------------------------------
POLYGON (( 2.00000000 2.00000000, 23.00000000 2.00000000,
23.00000000 15.00000000, 2.00000000 15.00000000, 2.00000000
2.00000000))