How the ST_Buffer Geometry Tool works, and what it assumes

ST_Buffer returns the area within a distance of a geometry: a disc around a point, a corridor along a line, a larger or smaller copy of a polygon. Curves are approximated with straight segments, eight per quarter circle by default as in PostGIS, and the end cap, join, mitre limit and side options match PostGIS's endcap, join, mitre_limit and side parameters. A negative distance shrinks an area instead of growing it.

Coordinate units are what ST_Buffer uses on a geometry: the distance is in the same unit as the coordinates. That is right for projected data in metres, and wrong for longitude and latitude, where it would be degrees. So for longitude and latitude the tool offers metres: the geometry is projected into an azimuthal equidistant projection on the WGS 84 ellipsoid, centred on the geometry, buffered there, and projected back to degrees. Distances from the centre are exact; elsewhere the projection stretches them slightly, and the page reports the largest stretch for your geometry.

For anything the size of a city that stretch is a few millionths; it passes 0.1 %, and the page warns, about 500 km from the centre, and the tool refuses beyond about 3,500 km rather than return a buffer that is visibly wrong. A buffer that would enclose a pole or cross the antimeridian is refused too, because a longitude and latitude polygon cannot represent it; buffer in a polar or local projected system instead.

Where this comes up in GIS work

  • Drawing a 500 m catchment around a school, a station or a shop.
  • Creating a safety or exclusion zone along a pipeline, road or power line.
  • Shrinking a parcel by a set-back distance with a negative buffer.
  • Producing the search area for a proximity query before running it in a database.

A worked example

A point buffered by 1 coordinate unit, and then a line with different end caps:

ST_Buffer('POINT (0 0)', 1)
  → a 32-sided polygon (33 positions), area 3.1214

ST_Buffer('LINESTRING (0 0, 10 0)', 1, 'endcap=flat')
  → POLYGON ((10 1, 10 -1, 0 -1, 0 1, 10 1)), area 20

The circle's area is 0.64 % below π because it is a polygon; with quad_segs=2 it becomes an octagon of area 2.8284. With the square end cap the line's buffer extends 1 unit past each end, for an area of 24, and side=left gives POLYGON ((10 0, 0 0, 0 1, 10 1, 10 0)), the strip on the left of the line's direction. A buffer of -2 on the 10 by 10 square gives the 6 by 6 square inside it.

Using the ST_Buffer Geometry Tool

  1. Paste a geometry as WKT, EWKT or GeoJSON, open a file, or select Load example.
  2. Enter the distance and choose Metres for longitude and latitude, or Coordinate units for projected data.
  3. Adjust the end cap, join, segments per quarter circle and side if you need to; the defaults match PostGIS.
  4. Select Buffer geometry, or press Ctrl + Enter (Cmd + Enter on a Mac).
  5. Check the plot and the measured area, then copy or download the buffer as WKT or GeoJSON.

When the output looks wrong

The buffer is a huge blob or covers the whole plot
The distance was taken in coordinate units on longitude and latitude, so 500 meant 500 degrees. Choose Metres, which measures the distance on the ground; the page warns whenever degrees are being used as a distance.
Metres on the WGS 84 ellipsoid need longitude and latitude in degrees
The coordinates are outside the degree range, so they are projected already. Choose Coordinate units: if the projection is in metres, the distance is in metres too.
The buffer would cover the North Pole
A polygon in longitude and latitude cannot enclose a pole. Reproject the geometry into a polar system such as EPSG:3413 or EPSG:3031 with ST_Transform and buffer in coordinate units there.
A negative buffer returned an empty geometry
A negative distance shrinks an area, and this one shrank to nothing. Points and lines have no area to shrink, so a negative or zero buffer of them is always empty, as in PostGIS.

Questions about the ST_Buffer Geometry Tool

How is a buffer in metres calculated for longitude and latitude?

The geometry is projected into an azimuthal equidistant projection on the WGS 84 ellipsoid, centred on the geometry, buffered there in metres and projected back. Distances from the centre are exact; the page reports the largest distortion elsewhere, which is well under 0.1 % for anything the size of a city and is refused beyond about 3,500 km.

Why is my circle a polygon with corners?

A buffer is built from straight segments. The default of 8 segments per quarter circle gives 32 around a point, whose area is about 0.6 % less than a true circle. Raise the segments for a smoother, larger file, or lower them for a coarser one.

What do the end cap and join options do?

The end cap shapes the ends of a buffered line: round, flat (cut off square at the end point) or square (extended by the distance). The join shapes the outside corners: round, mitre (sharp, limited by the mitre limit) or bevel (cut off). They match PostGIS's endcap, join and mitre_limit parameters.

What is a one-sided buffer?

A buffer on only the left or right of a line, relative to its direction, like PostGIS's side=left and side=right. It only applies to lines; for points and polygons the tool buffers both sides and says so.

Is my geometry uploaded?

No. The buffer is computed in your browser with JSTS and proj4js, both loaded from this site.