The SE_BoundingBox() function
The SE_BoundingBox() function returns a polygon which represents the spatial extent (the minimum and maximum X and Y values) of all the geometries in a spatial column of a table.
Important: You must have an R-tree index
on the spatial column.
Syntax
SE_BoundingBox (tablename varchar(128),
columnname varchar(128))
Return type
ST_Polygon
Example
The buildingfootprints table
is created with the following statement. The building_id column
uniquely identifies the buildings, the lot_id identifies the
building's lot, and the footprint multipolygon stores the building's
geometry:
CREATE TABLE buildingfootprints (building_id integer,
lot_id integer,
footprint ST_MultiPolygon);
After
the table is populated, create an R-tree index on the footprint column:
CREATE INDEX footprint_ix
ON buildingfootprints (footprint ST_Geometry_ops)
USING RTREE;
Use the SE_BoundingBox() function
to obtain a polygon that defines the spatial extent of all the polygons
in the table:
Obtaining
the Spatial Extent of a Functional IndexEXECUTE FUNCTION SE_BoundingBox ('buildingfootprints', 'footprint');
(expression) 1000 POLYGON ((7 22, 38 22, 38 55, 7 55, 7 22))
You cannot use the SE_BoundingBox() function
on a functional R-tree index. Instead, you must use the rtreeRootBB() function.
The rtreeRootBB() function takes the index name
and type name as arguments and returns the well-known text representation
of an ST_Polygon, as shown in the following example:
CREATE TABLE xytab (x float, y float, srid int);
INSERT INTO xytab VALUES (1, 2, 0);
INSERT INTO xytab VALUES (3, 4, 0);
CREATE INDEX point_idx ON xytab
(ST_Point(x,y,srid) ST_Geometry_ops) USING RTREE;
EXECUTE FUNCTION rtreeRootBB('point_idx', 'st_point');
(expression) 0 POLYGON ((1 2, 3 2, 3 4, 1 4, 1 2))