Skip to main content

buffer

Grows a geometry by distance metres on every side, giving the area within that distance of it: a ring around a point, a rounded strip along a line, a larger polygon around a polygon. A negative distance shrinks a polygon, and a collection becomes the union of its members' buffers.

This is a function exported by @mapcairn/core, checked against version 0.2.0.

Signature​

import { buffer } from "@mapcairn/core";

function buffer(input: GeometryInput, distance: number, options?: BufferOptions): PolygonalGeometry | null;

Description​

The result is null when nothing is left: a distance of 0 around a point or a line, or a negative distance that swallows the polygon. A distance of 0 returns a polygon as it is.

Distances are on the ground, worked out around each shape's own centre, so a buffer is round on the Earth rather than on a flat map. Limit: a buffer that would cross the antimeridian or enclose a pole is refused, because GeoJSON cannot write it as one ring. Such a ring has an edge that jumps more than 180 degrees of longitude, so a shape with an edge that long is refused too. Buffer a shape that is far from both, or split it first.

Parameters​

  • input (GeometryInput)
  • distance (number): Metres, finite. Negative only for a polygon.
  • options? (BufferOptions)

Returns​

PolygonalGeometry | null

Throws​

  • GeometryError of kind invalid for a malformed geometry, a distance or steps that is not valid, or a negative distance for a point or line; empty for a geometry with no positions; unsupported when the buffer would cross the antimeridian or enclose a pole.

See also​

Source: packages/core/src/geometry/operations.ts:137