Bounding Box Functions
These functions produce or operate on bounding boxes.
They can also provide and accept geometry values, by using automatic or explicit casts.
See also .
Box2D
Returns a BOX2D representing the 2D extent of a geometry.
box2d Box2D
geometry geom
Description
Returns a representing the 2D extent of the geometry.
Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.
&curve_support;
&P_support;
&T_support;
Examples
SELECT Box2D('LINESTRING(1 2,3 4,5 6)'::geometry);
BOX(1 2,5 6)
SELECT Box2D('CIRCULARSTRING(220268 150415,220227 150505,220227 150406)'::geometry);
BOX(220186.99512189245 150406,220288.24878054656 150506.12682932706)
See Also
,
Box3D
Returns a BOX3D representing the 3D extent of a geometry.
box3d Box3D
geometry geom
Description
Returns a representing the 3D extent of the geometry.
Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.
&curve_support;
&P_support;
&T_support;
&Z_support;
Examples
SELECT Box3D('LINESTRING(1 2 3,3 4 5,5 6 5)'::geometry);
BOX3D(1 2 3,5 6 5)
SELECT Box3D('CIRCULARSTRING(220268 150415 1,220227 150505 1,220227 150406 1)'::geometry);
BOX3D(220186.99512189245 150406 1,220288.24878054656 150506.12682932706 1)
See Also
,
ST_EstimatedExtent
Returns the estimated extent of a spatial table.
box2d ST_EstimatedExtent
text schema_name
text table_name
text geocolumn_name
boolean parent_only
box2d ST_EstimatedExtent
text schema_name
text table_name
text geocolumn_name
box2d ST_EstimatedExtent
text table_name
text geocolumn_name
Description
Returns the estimated extent of a spatial table as a .
The current schema is used if not specified.
The estimated extent is taken from the geometry column's statistics.
This is usually much faster than computing the exact extent of the table
using or .
The default behavior is to also use statistics collected from child tables (tables
with INHERITS) if available. If parent_only is set to TRUE, only
statistics for the given table are used and child tables are ignored.
For PostgreSQL >= 8.0.0 statistics are gathered by VACUUM
ANALYZE and the result extent will be about 95% of the actual one.
For PostgreSQL < 8.0.0 statistics are gathered by running
update_geometry_stats() and the result extent is exact.
In the absence of statistics (empty table or no ANALYZE called) this function
returns NULL. Prior to version 1.5.4 an exception was thrown instead.
Escaping names for tables and/or namespaces that include special characters and quotes may require special handling. A user notes: "For schemas and tables, use identifier escaping rules to produce a double-quoted string, and afterwards remove the first and last double-quote character. For geometry column pass as is."
Availability: 1.0.0
Changed: 2.1.0. Up to 2.0.x this was called ST_Estimated_Extent.
&curve_support;
Examples
SELECT ST_EstimatedExtent('ny', 'edges', 'geom');
st_estimatedextent
--------------------------------------------------
BOX(-8877653 4912316,-8010225.5 5589284)
(1 row)
SELECT ST_EstimatedExtent('feature_poly', 'geom');
st_estimatedextent
---------------------------------------------------------------------
BOX(-124.659652709961 24.6830825805664,-67.7798080444336 49.0012092590332)
(1 row)
See Also
,
ST_Expand
Returns a bounding box expanded from another bounding box or a geometry.
geometry ST_Expand
geometry geom
float units_to_expand
geometry ST_Expand
geometry geom
float dx
float dy
float dz=0
float dm=0
box2d ST_Expand
box2d box
float units_to_expand
box2d ST_Expand
box2d box
float dx
float dy
box3d ST_Expand
box3d box
float units_to_expand
box3d ST_Expand
box3d box
float dx
float dy
float dz=0
Description
Returns a bounding box expanded from the bounding box of the input,
either by specifying a single distance with which the box should be expanded on both
axes, or by specifying an expansion distance for each axis.
Uses double-precision. Can be used for distance queries, or to add a bounding box
filter to a query to take advantage of a spatial index.
In addition to the version of ST_Expand accepting and returning a geometry, variants
are provided that accept and return
and data types.
Distances are in the units of the spatial reference system of the input.
ST_Expand is similar to ,
except while buffering expands a geometry in all directions,
ST_Expand expands the bounding box along each axis.
Pre version 1.3, ST_Expand was used in conjunction with to do indexable distance queries. For example,
geom && ST_Expand('POINT(10 20)', 10) AND ST_Distance(geom, 'POINT(10 20)') < 10.
This has been replaced by the simpler and more efficient function.
Availability: 1.5.0 behavior changed to output double precision instead of float4 coordinates.
Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.
Enhanced: 2.3.0 support was added to expand a box by different amounts in different dimensions.
&P_support;
&T_support;
Examples
Examples below use US National Atlas Equal Area (SRID=2163) which is a meter projection
10-meter expanded box around bbox of a linestring.
SELECT CAST(ST_Expand(ST_GeomFromText('LINESTRING(2312980 110676,2312923 110701,2312892 110714)', 2163), 10) As box2d);
BOX(2312882 110666,2312990 110724)
This example expands a 3D box by 10 meters.
SELECT ST_Expand(CAST('BOX3D(778783 2951741 1,794875 2970042.61545891 10)' AS box3d), 10)
BOX3D(778773 2951731 -9,794885 2970052.61545891 20)
This example renders the text representation of a 10-meter expanded box around a point geometry.
SELECT ST_Expand('SRID=2163;POINT(2312980 110676)'::geometry, 10);
SRID=2163;POLYGON((2312970 110666,2312970 110686,2312990 110686,2312990 110666,2312970 110666))
See Also
, ,
ST_Extent
Aggregate function that returns the bounding box of geometries.
box2d ST_Extent
geometry set geomfield
Description
An aggregate function that returns a bounding box
that bounds a set of geometries.
The bounding box coordinates are in the spatial reference system of the input geometries.
ST_Extent is similar in concept to Oracle Spatial/Locator's SDO_AGGR_MBR.
ST_Extent returns boxes with only X and Y ordinates even with 3D geometries.
To return XYZ ordinates use .
The returned box3d value does not include a SRID.
Use to convert it into a geometry with SRID metadata.
The SRID is the same as the input geometries.
Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.
&P_support;
&T_support;
Examples
Examples below use Massachusetts State Plane ft (SRID=2249)
SELECT ST_Extent(geom) AS bextent FROM sometable;
BOX(739651.875 2908247.25,794875.8125 2970042.75)
Return extent of each geometry category.
SELECT ST_Extent(geom) as bextent
FROM sometable
GROUP BY category ORDER BY category;
bextent | name
----------------------------------------------------+----------------
BOX(778783.5625 2951741.25,794875.8125 2970042.75) | A
BOX(751315.8125 2919164.75,765202.6875 2935417.25) | B
BOX(739651.875 2917394.75,756688.375 2935866) | C
This example converts the extent back into a geometry and renders its extended text representation.
SELECT ST_SetSRID(ST_Extent(geom), 2249) AS bextent FROM sometable;
SRID=2249;POLYGON((739651.875 2908247.25,739651.875 2970042.75,794875.8125 2970042.75,
794875.8125 2908247.25,739651.875 2908247.25))
See Also
,
,
ST_3DExtent
Aggregate function that returns the 3D bounding box of geometries.
box3d ST_3DExtent
geometry set geomfield
Description
An aggregate function that returns a (includes Z ordinate) bounding box
that bounds a set of geometries.
The bounding box coordinates are in the spatial reference system of the input geometries.
The returned box3d value does not include a SRID.
Use to convert it into a geometry with SRID metadata.
The SRID is the same as the input geometries.
Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.
Changed: 2.0.0 In prior versions this used to be called ST_Extent3D
&Z_support;
&curve_support;
&P_support;
&T_support;
Examples
SELECT ST_3DExtent(foo.geom) As b3extent
FROM (SELECT ST_MakePoint(x, y, z) As geom
FROM generate_series(1, 3) As x
CROSS JOIN generate_series(1, 2) As y
CROSS JOIN generate_series(0, 2) As Z) As foo;
BOX3D(1 1 0,3 2 2)
This example returns the extent of several elevated CircularStrings.
SELECT ST_3DExtent(foo.geom) As b3extent
FROM (SELECT ST_Translate(ST_Force3DZ(ST_LineToCurve(ST_Buffer(ST_Point(x, y), 1))), 0, 0, z) As geom
FROM generate_series(1, 3) As x
CROSS JOIN generate_series(1, 2) As y
CROSS JOIN generate_series(0, 2) As Z) As foo;
BOX3D(0 0 0,4 3 2)
See Also
, ,
ST_MakeBox2D
Creates a BOX2D defined by two 2D point geometries.
box2d ST_MakeBox2D
geometry pointLowLeft
geometry pointUpRight
Description
Creates a defined by two Point
geometries. This is useful for doing range queries.
Examples
Return all features that fall within or partly reside in a US National Atlas coordinate bounding box. It is assumed here that the geometries are stored with SRID=2163 (US National Atlas equal area).
See Also
, ,
ST_3DMakeBox
Creates a BOX3D defined by two 3D point geometries.
box3d ST_3DMakeBox
geometry point3DLowLeftBottom
geometry point3DUpRightTop
Description
Creates a defined by two 3D Point
geometries.
This function supports 3D and will not drop the z-index.
Changed: 2.0.0 In prior versions this used to be called ST_MakeBox3D
Examples
SELECT ST_3DMakeBox(ST_MakePoint(-989502.1875, 528439.5625, 10),
ST_MakePoint(-987121.375 , 529933.1875, 10))
BOX3D(-989502.1875 528439.5625 10,-987121.375 529933.1875 10)
See Also
, ,
ST_XMax
Returns the X maxima of a 2D or 3D bounding box or a geometry.
float ST_XMax
box3d aGeomorBox2DorBox3D
Description
Returns the X maxima of a 2D or 3D bounding box or a geometry.
Although this function is only defined for box3d, it also works for box2d and geometry values due to automatic casting.
However, it will not accept a geometry or box2d text representation, since those do not auto-cast.
&Z_support;
&curve_support;
Examples
SELECT ST_XMax('BOX3D(1 2 3,4 5 6)');
4
SELECT ST_XMax('LINESTRING(1 3 4,5 6 7)'::geometry);
5
SELECT ST_XMax(CAST('BOX(-3 2,3 4)' AS box2d));
3
Observe THIS DOES NOT WORK because it will try to auto-cast the string representation to a BOX3D.
SELECT ST_XMax('LINESTRING(1 3,5 6)');
ERROR: BOX3D parser - doesn't start with BOX3D(
SELECT ST_XMax('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'::geometry);
220288.248780547
See Also
, , , , , ,
ST_XMin
Returns the X minima of a 2D or 3D bounding box or a geometry.
float ST_XMin
box3d aGeomorBox2DorBox3D
Description
Returns the X minima of a 2D or 3D bounding box or a geometry.
Although this function is only defined for box3d, it also works for box2d and geometry values due to automatic casting.
However it will not accept a geometry or box2d text representation, since those do not auto-cast.
&Z_support;
&curve_support;
Examples
SELECT ST_XMin('BOX3D(1 2 3,4 5 6)');
1
SELECT ST_XMin('LINESTRING(1 3 4,5 6 7)'::geometry);
1
SELECT ST_XMin(CAST('BOX(-3 2,3 4)' AS box2d));
-3
Observe THIS DOES NOT WORK because it will try to auto-cast the string representation to a BOX3D.
SELECT ST_XMin('LINESTRING(1 3,5 6)');
ERROR: BOX3D parser - doesn't start with BOX3D(
SELECT ST_XMin('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'::geometry);
220186.995121892
See Also
, , , , , ,
ST_YMax
Returns the Y maxima of a 2D or 3D bounding box or a geometry.
float ST_YMax
box3d aGeomorBox2DorBox3D
Description
Returns the Y maxima of a 2D or 3D bounding box or a geometry.
Although this function is only defined for box3d, it also works for box2d and geometry values due to automatic casting.
However it will not accept a geometry or box2d text representation, since those do not auto-cast.
&Z_support;
&curve_support;
Examples
SELECT ST_YMax('BOX3D(1 2 3,4 5 6)');
5
SELECT ST_YMax('LINESTRING(1 3 4,5 6 7)'::geometry);
6
SELECT ST_YMax(CAST('BOX(-3 2,3 4)' AS box2d));
4
Observe THIS DOES NOT WORK because it will try to auto-cast the string representation to a BOX3D.
SELECT ST_YMax('LINESTRING(1 3,5 6)');
ERROR: BOX3D parser - doesn't start with BOX3D(
SELECT ST_YMax('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'::geometry);
150506.126829327
See Also
, , , , , ,
ST_YMin
Returns the Y minima of a 2D or 3D bounding box or a geometry.
float ST_YMin
box3d aGeomorBox2DorBox3D
Description
Returns the Y minima of a 2D or 3D bounding box or a geometry.
Although this function is only defined for box3d, it also works for box2d and geometry values due to automatic casting.
However it will not accept a geometry or box2d text representation, since those do not auto-cast.
&Z_support;
&curve_support;
Examples
SELECT ST_YMin('BOX3D(1 2 3,4 5 6)');
2
SELECT ST_YMin('LINESTRING(1 3 4,5 6 7)'::geometry);
3
SELECT ST_YMin(CAST('BOX(-3 2,3 4)' AS box2d));
2
Observe THIS DOES NOT WORK because it will try to auto-cast the string representation to a BOX3D.
SELECT ST_YMin('LINESTRING(1 3,5 6)');
ERROR: BOX3D parser - doesn't start with BOX3D(
SELECT ST_YMin('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'::geometry);
150406
See Also
, , , , , , ,
ST_ZMax
Returns the Z maxima of a 2D or 3D bounding box or a geometry.
float ST_ZMax
box3d aGeomorBox2DorBox3D
Description
Returns the Z maxima of a 2D or 3D bounding box or a geometry.
Although this function is only defined for box3d, it also works for box2d and geometry values due to automatic casting.
However it will not accept a geometry or box2d text representation, since those do not auto-cast.
&Z_support;
&curve_support;
Examples
SELECT ST_ZMax('BOX3D(1 2 3,4 5 6)');
6
SELECT ST_ZMax('LINESTRING(1 3 4,5 6 7)'::geometry);
7
SELECT ST_ZMax('BOX3D(-3 2 1,3 4 1)');
1
Observe THIS DOES NOT WORK because it will try to auto-cast the string representation to a BOX3D.
SELECT ST_ZMax('LINESTRING(1 3 4,5 6 7)');
ERROR: BOX3D parser - doesn't start with BOX3D(
SELECT ST_ZMax('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'::geometry);
3
See Also
, , , , , , ,
ST_ZMin
Returns the Z minima of a 2D or 3D bounding box or a geometry.
float ST_ZMin
box3d aGeomorBox2DorBox3D
Description
Returns the Z minima of a 2D or 3D bounding box or a geometry.
Although this function is only defined for box3d, it also works for box2d and geometry values due to automatic casting.
However it will not accept a geometry or box2d text representation, since those do not auto-cast.
&Z_support;
&curve_support;
Examples
SELECT ST_ZMin('BOX3D(1 2 3,4 5 6)');
3
SELECT ST_ZMin('LINESTRING(1 3 4,5 6 7)'::geometry);
4
SELECT ST_ZMin('BOX3D(-3 2 1,3 4 1)');
1
Observe THIS DOES NOT WORK because it will try to auto-cast the string representation to a BOX3D.
SELECT ST_ZMin('LINESTRING(1 3 4,5 6 7)');
ERROR: BOX3D parser - doesn't start with BOX3D(
SELECT ST_ZMin('CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)'::geometry);
1
See Also
, , , , , , , ,
ST_XSize
Returns the X size of a 2D or 3D bounding box or a geometry.
float ST_XSize
box3d aGeomorBox2DorBox3D
Description
Returns the X size of a 2D or 3D bounding box or a geometry, computed as ST_XMax(aGeomorBox2DorBox3D) - ST_XMin(aGeomorBox2DorBox3D).
Although this function is only defined for box3d, it also works for box2d and geometry values due to automatic casting.
However it will not accept a geometry or box2d text representation, since those do not auto-cast.
&Z_support;
&curve_support;
Availability: 3.7.0
Examples
SELECT ST_XSize('BOX3D(1 2 3,4 5 6)');
3
SELECT ST_XSize('LINESTRING(1 3,5 6)'::geometry);
4
See Also
, , , ,
ST_YSize
Returns the Y size of a 2D or 3D bounding box or a geometry.
float ST_YSize
box3d aGeomorBox2DorBox3D
Description
Returns the Y size of a 2D or 3D bounding box or a geometry, computed as ST_YMax(aGeomorBox2DorBox3D) - ST_YMin(aGeomorBox2DorBox3D).
Although this function is only defined for box3d, it also works for box2d and geometry values due to automatic casting.
However it will not accept a geometry or box2d text representation, since those do not auto-cast.
&Z_support;
&curve_support;
Availability: 3.7.0
Examples
SELECT ST_YSize('BOX3D(1 2 3,4 5 6)');
3
SELECT ST_YSize('LINESTRING(1 3,5 6)'::geometry);
3
See Also
, , , ,
ST_ZSize
Returns the Z size of a 2D or 3D bounding box or a geometry.
float ST_ZSize
box3d aGeomorBox2DorBox3D
Description
Returns the Z size of a 2D or 3D bounding box or a geometry, computed as ST_ZMax(aGeomorBox2DorBox3D) - ST_ZMin(aGeomorBox2DorBox3D).
Although this function is only defined for box3d, it also works for box2d and geometry values due to automatic casting.
However it will not accept a geometry or box2d text representation, since those do not auto-cast.
&Z_support;
&curve_support;
Availability: 3.7.0
Examples
SELECT ST_ZSize('BOX3D(1 2 3,4 5 6)');
3
SELECT ST_ZSize('LINESTRING(1 3 4,5 6 7)'::geometry);
3
See Also
, , , ,
ST_MMin
Returns the M minima of a geometry.
float ST_MMingeometry geom
Description
Returns the M minima of a geometry, or null if the geometry lacks M values.
&Z_support;
&curve_support;
Examples
SELECT ST_MMin('POINT M (1 2 3)');
3
See Also
, , , , , , ,
ST_MMax
Returns the M maxima of a geometry.
float ST_MMaxgeometry geom
Description
Returns the M maxima of a geometry, or null if the geometry lacks M values.
&Z_support;
&curve_support;
Examples
SELECT ST_MMax('POINT M (1 2 3)');
3
See Also
, , , , , , ,
ST_MSize
Returns the M size of a geometry.
float ST_MSizegeometry geom
Description
Returns the M size of a geometry, computed as ST_MMax(geom) - ST_MMin(geom), or null if the geometry lacks M values.
&Z_support;
&curve_support;
Availability: 3.7.0
Examples
SELECT ST_MSize('LINESTRING M (1 2 3,4 6 8)');
5
See Also
, , , ,