turf.buffer
What is turf.buffer?
turf.buffer is a Turf.js function that calculates a buffer polygon around any GeoJSON Feature, FeatureCollection, or Geometry for a given distance and unit. It is the browser-side and Node.js equivalent of ST_Buffer and is the most common way to compute proximity zones in JavaScript mapping applications.
turf.buffer(geojson, radius, options?) → Feature<Polygon | MultiPolygon>Options include:
units—'kilometers'(default),'meters','miles','nauticalmiles','radians','degrees'steps— number of steps approximating a circle for point buffers (default 8)
Unlike PostGIS, Turf computes buffers in geodetic coordinates on the WGS84 ellipsoid, so distances are specified in real-world units (not degrees) regardless of the input's projection.
When would you use turf.buffer?
Use turf.buffer in web mapping applications where you need to compute proximity zones client-side without a round trip to a spatial database — for example, drawing a delivery radius on a MapLibre or Mapbox map as a user drags a marker, highlighting parcels within a selection distance, or generating isolation zones around clicked features in a public-safety dashboard.
It is also invaluable for pre-processing GeoJSON in build pipelines — creating trail corridors, bike-lane setbacks, or administrative buffer zones as static tilesets that ship with a site. For Node.js ETL workflows that output GeoJSON, turf.buffer avoids spinning up PostGIS entirely.
FAQs
How accurate is turf.buffer?
turf.buffer uses a geodesic calculation on the WGS84 ellipsoid, so distances are accurate to within a few centimetres at typical urban scales. For very large buffers (hundreds of kilometres) or high-latitude regions, accuracy degrades slightly — if you need survey-grade precision at those scales, a projected PostGIS buffer is more reliable.
How do I install Turf.js to use this function?
You can install the full Turf library or just the buffer module. For tree-shaking, prefer the scoped package: npm install @turf/buffer. In a browser, you can also include the full bundle from a CDN such as unpkg or jsDelivr. Usage is the same in both environments — call turf.buffer(feature, 500, { units: 'meters' }).
Why are my point buffers not perfectly circular on the map?
The polygon approximating a circle has steps × 4 vertices (default 32). If you are rendering at high zoom, increase steps to 64 or 128 for smoother circles. Note that the buffer is computed geodetically — when rendered in Web Mercator (EPSG:3857), circles away from the equator appear slightly stretched. That is a projection artefact, not a Turf issue.
Can I buffer a FeatureCollection in one call?
Yes. turf.buffer accepts a FeatureCollection and returns a FeatureCollection of buffered features in the same order. Each feature is buffered independently — if you want a single merged buffer, pass the result through turf.union or turf.dissolve afterwards.