Skip to main content

buffer

Creates a buffer around a geometry with a specified distance. Distance is in input geometry units.

Parameters

NameTypeDefaultDescription
geometryGeometryThe geometry to buffer
distancenumberThe buffer distance. Positive values expand the geometry, negative values shrink it
options?objectOptional parameters to control buffer generation
options.quadrantSegments?number8The default number of facets into which to divide a fillet of 90 degrees.
A value of 8 gives less than 2% max error in the buffer distance. For a max error of < 1%, use QS = 12. For a max error of < 0.1%, use QS = 18. The error is always less than the buffer distance.
options.endCapStyle?'round' | 'flat' | 'square''round'Cap styles control the ends of buffered lines.
  • round - End is rounded, with end point of original line in the center of the round cap.
  • flat - End is flat, with end point of original line at the end of the buffer.
  • square - End is flat, with end point of original line in the middle of a square enclosing that point.
options.joinStyle?'round' | 'mitre' | 'bevel''round'Join styles control the buffer shape at bends in a line.
  • round - Join is rounded, essentially each line is terminated in a round cap. Form round corner.
  • mitre - Join is flat, with line between buffer edges, through the join point. Forms flat corner.
  • bevel - Join is the point at which the two buffer edges intersect. Forms sharp corner.
options.mitreLimit?number5.0For acute angles, a mitre join can extend very very far from the input geometry, which is probably not desired. The mitre limit places an upper bound on that.
options.singleSided?booleanfalseSets whether the computed buffer should be single-sided. A single-sided buffer is constructed on only one side of each input line.
The side used is determined by the sign of the buffer distance:
  • a positive distance indicates the left-hand side
  • a negative distance indicates the right-hand side
The single-sided buffer of point geometries is the same as the regular buffer.
The endCapStyle for single-sided buffers is always ignored and forced to the equivalent of flat.

Returns

Polygon | MultiPolygon

A new, buffered, geometry

Throws

  • GEOSError on unsupported geometry types (curved)

Examples

create a simple buffer around a point
create a buffer around a line
create a buffer that shrinks the geometry