- 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¶
Arguments¶
geometry_expressionThe argument must be an expression of type GEOMETRY.
distanceThe 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
distanceis 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.
- LineStrings are always buffered on both sides.
Examples¶
Before executing the examples, set the GEOMETRY_OUTPUT_FORMAT parameter to WKT:
Buffer a Point¶
Buffering a Point returns a MultiPolygon that approximates a circle around the Point. Because ST_BUFFER uses eight
segments to approximate each quarter circle, the circle is drawn with 32 straight segments (33 points, because the ring
repeats its starting point). The area is therefore slightly smaller than the area of a true circle
(PI() * 1 * 1, or about 3.1416).
The following example buffers a Point by a distance of 1 and reports the number of points and the area of the result:
To see the full shape, select the buffer directly (for example, SELECT ST_BUFFER(TO_GEOMETRY('POINT(0 0)'), 1)).
The output is a MultiPolygon with a long list of coordinates for the 32 segments that approximate the circle.
Buffer a LineString¶
ST_BUFFER buffers a LineString on both sides and uses round endcaps, so the result is a capsule-shaped MultiPolygon.
The following example buffers a line that is 10 units long by a distance of 2:
The area is the rectangle along the line (10 units long and 4 units wide, for 40 square units) plus the two rounded ends,
which together approximate a circle with a radius of 2.
Specify the distance in meters¶
The units of distance depend on the SRID of the input object. The following example
buffers a Point in SRID 32633 (UTM zone 33N, which uses meters) by 100 meters. The resulting area is close to the area
of a circle with a 100-meter radius (PI() * 100 * 100, or about 31416 square meters):
Shrink a shape with a negative distance¶
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.