ST_Buffer¶
Introduction: Returns a geometry/geography that represents all points whose distance from this Geometry/geography is less than or equal to distance. The function supports both Planar/Euclidean and Spheroidal/Geodesic buffering (Since v1.6.0). Spheroidal buffer also supports geometries crossing the International Date Line (IDL).
Mode of buffer calculation (Since: v1.6.0):
The optional third parameter, useSpheroid, controls the mode of buffer calculation.
- Planar Buffering (default): When
useSpheroidis false,ST_Bufferperforms standard planar buffering based on the provided parameters. - Spheroidal Buffering:
- When
useSpheroidis set to true, the function returns the spheroidal buffer polygon for more accurate representation over the Earth. In this mode, the unit of the buffer distance is interpreted as meters. - ST_Buffer first determines the most appropriate Spatial Reference Identifier (SRID) for a given geometry, based on its spatial extent and location, using
ST_BestSRID. - The geometry is then transformed from its original SRID to the selected SRID. If the input geometry does not have a set SRID,
ST_Bufferdefaults to using WGS 84 (SRID 4326) as its original SRID. - The standard planar buffer operation is then applied in this coordinate system.
- Finally, the buffered geometry is transformed back to its original SRID, or to WGS 84 if the original SRID was not set.
- When
Note
Spheroidal buffering only supports lon/lat coordinate systems and will throw an IllegalArgumentException for input geometries in meter based coordinate systems.
Note
Spheroidal buffering may not produce accurate output buffer for input geometries larger than a UTM zone.
Buffer Style Parameters:
The optional forth parameter controls the buffer accuracy and style. Buffer accuracy is specified by the number of line segments approximating a quarter circle, with a default of 8 segments. Buffer style can be set by providing blank-separated key=value pairs in a list format.
quad_segs=#: Number of line segments utilized to approximate a quarter circle (default is 8).endcap=round|flat|square: End cap style (default isround).buttis an accepted synonym forflat.join=round|mitre|bevel: Join style (default isround).miteris an accepted synonym formitre.mitre_limit=#.#: mitre ratio limit and it only affects mitred join style.miter_limitis an accepted synonym formitre_limit.side=both|left|right: Defaults toboth. Settingleftorrightenables a single-sided buffer operation on the geometry, with the buffered side aligned according to the direction of the line. This functionality is specific to LINESTRING geometry and has no impact on POINT or POLYGON geometries. By default, square end caps are applied whenleftorrightare specified.
Note
ST_Buffer throws an IllegalArgumentException if the correct format, parameters, or options are not provided.
Format:
ST_Buffer (A: Geometry, buffer: Double)
ST_Buffer (A: Geometry, buffer: Double, useSpheroid: Boolean)
ST_Buffer (A: Geometry, buffer: Double, useSpheroid: Boolean, bufferStyleParameters: String)
Since: v1.5.1
SQL Example:
SELECT ST_Buffer(ST_GeomFromWKT('POINT(0 0)'), 10)
SELECT ST_Buffer(ST_GeomFromWKT('POINT(0 0)'), 10, false, 'quad_segs=2')
Output:

8 Segments 2 Segments
SQL Example:
SELECT ST_Buffer(ST_GeomFromWKT('LINESTRING(0 0, 50 70, 100 100)'), 10, false, 'side=left')
Output:

Original Linestring Left side buffed Linestring