类别:

地理空间函数

ST_BUFFER

返回一个表示 MultiPolygon 的 GEOMETRY 对象,该多边形包含输入 GEOMETRY 对象指定距离内的点。返回的对象有效表示输入对象周围的一个“缓冲区”。

您还可以通过指定负的距离值来“缩小”输入对象。

语法

ST_BUFFER( <geometry_expression> , <distance> )
Copy

实参

geometry_expression

实参必须是 GEOMETRY 类型的表达式。

distance

与 GEOMETRY 对象的距离。要“缩小”对象,可以指定负的距离值。

返回

返回一个 GEOMETRY 对象。

使用说明

  • ST_BUFFER 使用八个段来模拟四分之一圆。

  • 如果 distance 为负值,则返回的对象将小于输入对象。可以利用这一点来消除形状中微小的不规则性。

  • 对于 LineStrings,端盖和联接样式始终是圆形。

  • LineStings 始终在两侧缓冲。

示例

以下示例返回一个围绕着点且半径为 1 的多边形:

SELECT ST_BUFFER(TO_GEOMETRY('POINT(0 0)'), 1);

+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ST_BUFFER(TO_GEOMETRY('POINT(0 0)'), 1) |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| MULTIPOLYGON(((1 0,0.9807852804 -0.195090322,0.9238795325 -0.3826834324,0.8314696123 -0.555570233,0.7071067812 -0.7071067812,0.555570233 -0.8314696123,0.3826834324 -0.9238795325,0.195090322 -0.9807852804,6.123233996e-17 -1,-0.195090322 -0.9807852804,-0.3826834324 -0.9238795325,-0.555570233 -0.8314696123,-0.7071067812 -0.7071067812,-0.8314696123 -0.555570233,-0.9238795325 -0.3826834324,-0.9807852804 -0.195090322,-1 7.657137398e-16,-0.9807852804 0.195090322,-0.9238795325 0.3826834324,-0.8314696123 0.555570233,-0.7071067812 0.7071067812,-0.555570233 0.8314696123,-0.3826834324 0.9238795325,-0.195090322 0.9807852804,2.480838239e-15 1,0.195090322 0.9807852804,0.3826834324 0.9238795325,0.555570233 0.8314696123,0.7071067812 0.7071067812,0.8314696123 0.555570233,0.9238795325 0.3826834324,0.9807852804 0.195090322,1 0))) |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Copy

以下示例使用负的 distance 值从形状中消除微小的不规则性(如尖峰)。请注意,TO_GEOMETRY 调用将 TRUE 作为第二个实参传入,从而允许函数为 无效的形状 创建一个 GEOMETRY 对象。

SELECT ST_BUFFER(TO_GEOMETRY('SRID=2261;POLYGON((1540792.21541900 290472.63529214, 1547018.61770388 302537.02285369, 1546965.96550151 302752.51514772, 1547018.61770388 302537.02285369,
1549532.42729914 301257.07398027, 1543327.42218339 289322.60923536, 1540792.21541900 290472.63529214))', True), -1e-08) AS geom;

+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                                                        GEOM |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| MULTIPOLYGON(((1543327.42218339 289322.609235373,1540792.21541901 290472.635292145,1547018.61770388 302537.022853677,1549532.42729913 301257.073980266,1543327.42218339 289322.609235373))) |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Copy
语言: 中文