ST_Buffer

更新时间:
复制 MD 格式

Returns a geometry object representing all points within a specified distance from the input geometry object. The result is the buffer zone surrounding the input. Calculations are based on the spatial reference system (SRS) of the input object.

Syntax

geometry  ST_Buffer(geometry  g1 , float radiusOfBuffer);
geometry  ST_Buffer(geometry g1 , float radiusOfBuffer , integer numSegQuarterCircle);
geometry  ST_Buffer(geometry g1 , float radiusOfBuffer , text bufferStyleParameters);
geography ST_Buffer(geography g1 , float radiusOfBufferInMeters);
geography ST_Buffer(geography g1 , float radiusOfBuffer , integer numSegQuarterCircle);
geography ST_Buffer(geography g1 , float radiusOfBuffer , text bufferStyleParameters);

Parameters

ParameterDescription
g1The geometry or geography object.
radiusOfBufferThe buffer radius. Valid only for geometry objects.
numSegQuarterCircleThe number of segments per quarter circle. Default value: 7.
bufferStyleParametersStyle options as space-separated key-value pairs. See Buffer style parameters.
radiusOfBufferInMetersThe buffer radius in meters. Valid only for geography objects.

Usage notes

Negative radius (polygon shrink)

For polygon objects, a negative radius shrinks the polygon instead of expanding it.

Geography object processing

For geography objects, radiusOfBuffer is measured in the unit defined by the SRS. Internally, ST_Buffer selects the best-fit Spatial Reference Identifier (SRID) for the object's bounding box, preferring coordinate systems in this order: Universal Transverse Mercator (UTM), Lambert Azimuthal Equal Area (LAEA), Universal Polar Stereographic (UPS), and Mercator projection as a last resort. Buffers are calculated in that SRS, then transformed back to World Geodetic System 1984 (WGS 84).

3D geometry

ST_Buffer ignores z coordinates. A 3D geometry input returns a 2D buffer geometry.

Radius searches

ST_Buffer is sometimes used for radius searches, but this approach is slow and unnecessary. Use ST_DWithin for radius searches instead.

Buffer style parameters

Pass style options as space-separated key-value pairs in bufferStyleParameters. For example: 'quad_segs=4 endcap=flat'.

  • quad_segs=<integer> — Number of line segments used to approximate a quarter circle. Default: 8. A higher value produces a smoother curve.

  • endcap=round|flat|square — Endcap style for LineString buffers. Default: round.

  • join=round|mitre|bevel — Join style at vertices. Default: round.

  • mitre_limit=<float> — Maximum mitre ratio. Default: 5.0. Applies only when join=mitre.

  • side=both|left|right — Which side to buffer. Applies only to LineString objects; has no effect on point or polygon objects. When set to left or right, the buffer is applied to one side only, relative to the direction of the line.

Examples

quad_segs — controlling curve smoothness

SELECT ST_Buffer('POINT(0 0)'::geometry,1),ST_Buffer('POINT(3 0)'::geometry,1,'quad_segs=2');
1

endcap — line endpoint shape

SELECT ST_Buffer('LINESTRING(0 0,0 3)'::geometry,1,'endcap=round'),
            ST_Buffer('LINESTRING(6 0,6 3)'::geometry,1,'endcap=flat'),
         ST_Buffer('LINESTRING(12 0,12 3)'::geometry,1,'endcap=square');
2

join — vertex join style

SELECT ST_Buffer('LINESTRING(0 0,3 0,3 3)'::geometry,1.2,'join=round'),
         ST_Buffer('LINESTRING(6 0,9 0,9 3)'::geometry,1.2,'join=mitre'),
         ST_Buffer('LINESTRING(12 0,15 0,15 3)'::geometry,1.2,'join=bevel');
3

mitre_limit — controlling mitre spike length

SELECT ST_Buffer('LINESTRING(0 0,3 0,3 3)'::geometry,1.2,'join=mitre mitre_limit=1.0'),
         ST_Buffer('LINESTRING(6 0,9 0,9 3)'::geometry,1.2,'join=mitre mitre_limit=0.5'),
         ST_Buffer('LINESTRING(12 0,15 0,15 3)'::geometry,1.2,'join=mitre mitre_limit=0.1');
4

side — single-sided buffering

SELECT ST_Buffer('LINESTRING(0 0,3 0,3 3,0 3)'::geometry,1,'side=both'),
       ST_Buffer('LINESTRING(6 0,9 0,9 3,6 3)'::geometry,1,'side=right'),
       ST_Buffer('LINESTRING(12 0,15 0,15 3,12 3)'::geometry,1,'side=left');
5