ST_Buffer
What is ST_Buffer?
ST_Buffer is a PostGIS function that returns a geometry covering all points within a given distance from the input geometry. It is the standard way to create buffer zones around points, lines, or polygons in a PostGIS database and powers most proximity-based spatial queries.
1ST_Buffer(geometry geom, float distance) → geometry
2ST_Buffer(geometry geom, float distance, text style_parameters) → geometry
3ST_Buffer(geography geog, float distance_meters) → geographyThe distance is measured in the units of the geometry's spatial reference system — for EPSG:4326 that is degrees, while projected CRSs like UTM use metres. When called on a geography type, distance is always in metres.
When would you use ST_Buffer?
Use ST_Buffer whenever you need a proximity or influence zone around a feature stored in PostGIS — defining a 500-metre catchment around transit stops, a flood-risk corridor along rivers, service areas for public facilities, or safety setbacks around hazardous sites. It is also the building block for more complex spatial joins when combined with ST_Intersects, and for corridor analyses along linear infrastructure such as pipelines, power lines, or roads.
In cartographic workflows, ST_Buffer with a small negative distance is a common trick for shrinking polygons inward to create inset labels, avoid coastline clutter, or generate pseudo-centerlines inside narrow features.
FAQs
What units does the distance parameter use?
Distance is measured in the units of the geometry's spatial reference system. For EPSG:4326 that is degrees (rarely what you want for real-world distances), while projected CRSs such as UTM or EPSG:3857 use metres. If you need metre-accurate buffers on lat/lon data, cast to geography first: ST_Buffer(geom::geography, 500).
Can I buffer on only one side of a line?
Yes. Pass a style parameter: ST_Buffer(geom, distance, 'side=left') or 'side=right'. Style parameters also control end caps (round, flat, square) and join style (round, mitre, bevel), which is useful for generating road setbacks or one-sided flood corridors.
How do I speed up ST_Buffer on large datasets?
Buffer computation scales with vertex count and can become a bottleneck. For distance tests, prefer ST_DWithin — it uses spatial indexes and avoids materializing geometry. If you only need an approximate buffer, reduce the quad_segs parameter (fewer segments per quarter circle) or simplify input geometry with ST_Simplify before buffering.
Why does ST_Buffer return a polygon even for points?
ST_Buffer always returns a polygonal geometry because the "buffer" is defined as the area within a distance threshold. For a point, that area is a circle approximated by a polygon with quad_segs vertices per quarter circle (8 by default, so 32 sides total).