ST_Buffer — 计算覆盖距几何体给定距离内所有点的几何体。
geometry ST_Buffer(
geometry g1, float radius_of_buffer, text buffer_style_parameters = '')
;
geometry ST_Buffer(
geometry g1, float radius_of_buffer, integer num_seg_quarter_circle)
;
geography ST_Buffer(
geography g1, float radius_of_buffer, text buffer_style_parameters)
;
geography ST_Buffer(
geography g1, float radius_of_buffer, integer num_seg_quarter_circle)
;
计算表示与几何/地理距离小于或等于给定距离的所有点的 POLYGON 或 MULTIPOLYGON。 负距离会缩小几何图形而不是扩展它。 负距离可能会完全缩小多边形,在这种情况下返回 POLYGON EMPTY。 对于点和线,负距离始终返回空结果。
对于几何体,距离以几何体的空间参考系的单位指定。 对于地理,距离以米为单位指定。
可选的第三个参数控制缓冲区的精度和样式。 缓冲区中圆弧的精度指定为用于近似四分之一圆的线段数(默认值为 8)。 可以通过提供空白分隔的键=值对列表来指定缓冲区样式,如下所示:
'quad_segs=#' :用于近似四分之一圆的线段数(默认为 8)。
'endcap=round|flat|square' :endcap 样式(默认为“round”)。 “butt”被认为是“flat”的同义词。
'join=round|mitre|bevel' :连接样式(默认为“round”)。 “mitre”被认为是“mitre”的同义词。
'mitre_limit=#.#' :斜接比率限制(仅影响斜接连接样式)。 “miter_limit”被接受为“mitre_limit”的同义词。
'side=both|left|right' : defaults to 'both'. 'left' or 'right' performs a single-sided buffer on the geometry, with the buffered side relative to the direction of the line. This is only applicable to LINESTRING geometry and does not affect POINT or POLYGON geometries. By default end caps are square when 'left' or 'right' are specified.
![]() |
|
|
![]() |
|
缓冲区操作可处理无效输入,并始终生成有效的多边形几何对象。以距离 0 进行缓冲常被用作修复无效多边形的一种方法。但对于此类修复操作,ST_MakeValid 更为适合,因为它能处理多面体MultiPolygon类型。 |
![]() |
|
缓冲有时用于执行近距离搜索。 对于此用例,使用ST_DWithin效率更高。 |
![]() |
|
此函数忽略 Z 维度。 即使在 3D 几何体上使用时,它也始终给出 2D 结果。 |
增强:2.5.0 - ST_Buffer的几何感知版本已得到增强,允许您指定要缓冲的一侧。side=both|left|right
。
可用性:1.5 - ST_Buffer 已得到增强,以适应各种端接和接缝。 例如,您可能希望将道路线串转换为街道面,并希望将端点视为平面或正方形而不是圆。 添加了地理的薄包装器。
这个函数是由 GEOS 模块执行的。
此方法实现了 SQL 1.1 的 OGC 简单功能规范。 s2.1.1.3
该方法实现了SQL/MM规范。 SQL-MM IEC 13249-3: 5.1.30
![]() quad_segs=8 (默认)
SELECT ST_Buffer( ST_GeomFromText('POINT(100 90)'), 50, 'quad_segs=8');
|
![]() quad_secs=2(不足)
SELECT ST_Buffer( ST_GeomFromText('POINT(100 90)'), 50, 'quad_segs=2');
|
|
![]() endcap=round join=round (默认)
SELECT ST_Buffer( ST_GeomFromText( 'LINESTRING(50 50,150 150,150 50)' ), 10, 'endcap=round join=round');
|
![]() endcap=square
SELECT ST_Buffer( ST_GeomFromText( 'LINESTRING(50 50,150 150,150 50)' ), 10, 'endcap=square join=round');
|
![]() endcap=flat
SELECT ST_Buffer( ST_GeomFromText( 'LINESTRING(50 50,150 150,150 50)' ), 10, 'endcap=flat join=round');
|
![]() join=bevel
SELECT ST_Buffer( ST_GeomFromText( 'LINESTRING(50 50,150 150,150 50)' ), 10, 'join=bevel');
|
![]() join=mitre mitre_limit=5.0 (默认最大斜接比率)
SELECT ST_Buffer( ST_GeomFromText( 'LINESTRING(50 50,150 150,150 50)' ), 10, 'join=mitre mitre_limit=5.0');
|
![]() join=mitre mitre_limit=1
SELECT ST_Buffer( ST_GeomFromText( 'LINESTRING(50 50,150 150,150 50)' ), 10, 'join=mitre mitre_limit=1.0');
|
![]() side=left
SELECT ST_Buffer( ST_GeomFromText( 'LINESTRING(50 50,150 150,150 50)' ), 10, 'side=left');
|
![]() side=right
SELECT ST_Buffer( ST_GeomFromText( 'LINESTRING(50 50,150 150,150 50)' ), 10, 'side=right');
|
![]() side=left join=mitre
SELECT ST_Buffer( ST_GeomFromText( 'LINESTRING(50 50,150 150,150 50)' ), 10, 'side=left join=mitre');
|
![]() 顺时针方向,多边形边界向左
SELECT ST_Buffer( ST_ForceRHR( ST_Boundary( ST_GeomFromText( 'POLYGON ((50 50, 50 150, 150 150, 150 50, 50 50))'))), ), 20, 'side=left');
|
![]() 顺时针方向,多边形边界向右
SELECT ST_Buffer( ST_ForceRHR( ST_Boundary( ST_GeomFromText( 'POLYGON ((50 50, 50 150, 150 150, 150 50, 50 50))')) ), 20,'side=right')
|
--A buffered point approximates a circle -- A buffered point forcing approximation of (see diagram) -- 2 points per quarter circle is poly with 8 sides (see diagram) SELECT ST_NPoints(ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50)) As promisingcircle_pcount, ST_NPoints(ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50, 2)) As lamecircle_pcount; promisingcircle_pcount | lamecircle_pcount ------------------------+------------------- 33 | 9 --A lighter but lamer circle -- only 2 points per quarter circle is an octagon --Below is a 100 meter octagon -- Note coordinates are in NAD 83 long lat which we transform to Mass state plane meter and then buffer to get measurements in meters; SELECT ST_AsText(ST_Buffer( ST_Transform( ST_SetSRID(ST_Point(-71.063526, 42.35785),4269), 26986) ,100,2)) As octagon; ---------------------- POLYGON((236057.59057465 900908.759918696,236028.301252769 900838.049240578,235 957.59057465 900808.759918696,235886.879896532 900838.049240578,235857.59057465 900908.759918696,235886.879896532 900979.470596815,235957.59057465 901008.759918 696,236028.301252769 900979.470596815,236057.59057465 900908.759918696))