- Categories:
ST_BUFFER¶
Returns a GEOMETRY object that represents a MultiPolygon containing the points within a specified distance of the input GEOMETRY object. The returned object effectively represents a “buffer” around the input object.
You can also “shrink” the input object by specifying a negative value for the distance.
Syntax¶
ST_BUFFER( <geometry_expression> , <distance> )
Arguments¶
geometry_expression
The argument must be an expression of type GEOMETRY.
distance
The distance from the GEOMETRY object. To “shrink” the object, you can specify a negative value for the distance.
The units depend on the spatial reference system identifier (SRID) of the GEOMETRY object. For example, ESPG:4326 units are degrees, while ESPG:25855 units are meters.
Returns¶
Returns a GEOMETRY object.
Usage notes¶
SRIDs are based on the EPSG standard (v10.082). For example, the SRID 4326 corresponds to the authority EPSG with the code 4326.
ST_BUFFER uses eight segments to approximate a quarter circle.
If
distance
is a negative value, the returned object is smaller than the input object. You can use this to remove small irregularities from the shape.For LineStrings, the endcap and join styles are always round.
LineStings are always buffered on both sides.
Examples¶
Before executing the examples, set the GEOMETRY_OUTPUT_FORMAT parameter to WKT
:
ALTER SESSION SET GEOMETRY_OUTPUT_FORMAT='WKT';
The following example returns a Polygon around a Point with a radius of one:
SELECT ST_BUFFER(TO_GEOMETRY('POINT(0 0)'), 1) AS geom;
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GEOM |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| MULTIPOLYGON(((1 0,0.9807852804 -0.195090322,0.9238795325 -0.3826834324,0.8314696123 -0.555570233,0.7071067812 -0.7071067812,0.555570233 -0.8314696123,0.3826834324 -0.9238795325,0.195090322 -0.9807852804,6.123233996e-17 -1,-0.195090322 -0.9807852804,-0.3826834324 -0.9238795325,-0.555570233 -0.8314696123,-0.7071067812 -0.7071067812,-0.8314696123 -0.555570233,-0.9238795325 -0.3826834324,-0.9807852804 -0.195090322,-1 7.657137398e-16,-0.9807852804 0.195090322,-0.9238795325 0.3826834324,-0.8314696123 0.555570233,-0.7071067812 0.7071067812,-0.555570233 0.8314696123,-0.3826834324 0.9238795325,-0.195090322 0.9807852804,2.480838239e-15 1,0.195090322 0.9807852804,0.3826834324 0.9238795325,0.555570233 0.8314696123,0.7071067812 0.7071067812,0.8314696123 0.555570233,0.9238795325 0.3826834324,0.9807852804 0.195090322,1 0))) |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
The following example uses a negative value for distance
to remove small irregularities (such as spikes) from the shape.
The TO_GEOMETRY call passes in TRUE as the second argument, which allows the function to create a GEOMETRY
object for an invalid shape.
SELECT ST_BUFFER(TO_GEOMETRY('SRID=2261;POLYGON((
1540792.21541900 290472.63529214, 1547018.61770388 302537.02285369,
1546965.96550151 302752.51514772, 1547018.61770388 302537.02285369,
1549532.42729914 301257.07398027, 1543327.42218339 289322.60923536,
1540792.21541900 290472.63529214))', True), -1e-08) AS geom;
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GEOM |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| MULTIPOLYGON(((1543327.42218339 289322.609235373,1540792.21541901 290472.635292145,1547018.61770388 302537.022853677,1549532.42729913 301257.073980266,1543327.42218339 289322.609235373))) |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+