Skip to content
🎉 Apache Sedona 1.8.1 is now available! Check out the new features and improvements.

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 useSpheroid is false, ST_Buffer performs standard planar buffering based on the provided parameters.
  • Spheroidal Buffering:
    • When useSpheroid is 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_Buffer defaults 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.

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 is round). butt is an accepted synonym for flat.
  • join=round|mitre|bevel : Join style (default is round). miter is an accepted synonym for mitre.
  • mitre_limit=#.# : mitre ratio limit and it only affects mitred join style. miter_limit is an accepted synonym for mitre_limit.
  • side=both|left|right : Defaults to both. Setting left or right enables 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 when left or right are 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)

Output:

Original Linestring Original Linestring with buffer on the left side

Original Linestring   Left side buffed Linestring