ST_Buffer
ST_Buffer 返回 2D 几何体,该几何表示与 xy 笛卡尔平面上投影的输入几何体之间的距离小于或等于输入距离的所有点。
语法
ST_Buffer(geom, distance)
ST_Buffer(geom, distance, number_of_segments_per_quarter_circle)
参数
- geom
-
一个
GEOMETRY
数据类型的值,或一个计算结果为GEOMETRY
类型的表达式。 - distance
-
数据类型
DOUBLE PRECISION
的值表示缓冲区的距离(或半径)。 - number_of_segments_per_quarter_circle
-
数据类型
INTEGER
的值。此值确定了围绕输入几何体的每个顶点大致四分之一圆的点数。负值默认为零。默认值为 8。
返回类型
GEOMETRY
ST_Buffer 函数返回 xy 笛卡尔平面中的二维 (2D) 几何体。
如果 geom 为 GEOMETRYCOLLECTION
,则返回一个错误。
示例
以下 SQL 返回输入线串的缓冲区。
SELECT ST_AsEwkt(ST_Buffer(ST_GeomFromText('LINESTRING(1 2,5 2,5 8)'), 2));
st_asewkt
POLYGON((-1 2,-0.96157056080646 2.39018064403226,-0.847759065022573 2.76536686473018,-0.662939224605089 3.11114046603921,-0.414213562373093 3.4142135623731,-0.111140466039201 3.66293922460509,0.234633135269824 3.84775906502257,0.609819355967748 3.96157056080646,1 4,3 4,3 8,3.03842943919354 8.39018064403226,3.15224093497743 8.76536686473018,3.33706077539491 9.11114046603921,3.58578643762691 9.4142135623731,3.8888595339608 9.66293922460509,4.23463313526982 9.84775906502257,4.60981935596775 9.96157056080646,5 10,5.39018064403226 9.96157056080646,5.76536686473018 9.84775906502257,6.11114046603921 9.66293922460509,6.4142135623731 9.41421356237309,6.66293922460509 9.1111404660392,6.84775906502258 8.76536686473017,6.96157056080646 8.39018064403225,7 8,7 2,6.96157056080646 1.60981935596774,6.84775906502257 1.23463313526982,6.66293922460509 0.888859533960796,6.41421356237309 0.585786437626905,6.1111404660392 0.33706077539491,5.76536686473018 0.152240934977427,5.39018064403226 0.0384294391935391,5 0,1 0,0.609819355967744 0.0384294391935391,0.234633135269821 0.152240934977427,-0.111140466039204 0.337060775394909,-0.414213562373095 0.585786437626905,-0.662939224605091 0.888859533960796,-0.847759065022574 1.23463313526982,-0.961570560806461 1.60981935596774,-1 2))
以下 SQL 返回输入点几何体的缓冲区,该缓冲区大致为一个圆。由于该命令没有指定每个四分之一圆的区段数,因此该函数使用八个区段的默认值表示约四分之一圆。
SELECT ST_AsEwkt(ST_Buffer(ST_GeomFromText('POINT(3 4)'), 2));
st_asewkt
POLYGON((1 4,1.03842943919354 4.39018064403226,1.15224093497743 4.76536686473018,1.33706077539491 5.11114046603921,1.58578643762691 5.4142135623731,1.8888595339608 5.66293922460509,2.23463313526982 5.84775906502257,2.60981935596775 5.96157056080646,3 6,3.39018064403226 5.96157056080646,3.76536686473019 5.84775906502257,4.11114046603921 5.66293922460509,4.4142135623731 5.41421356237309,4.66293922460509 5.1111404660392,4.84775906502258 4.76536686473017,4.96157056080646 4.39018064403225,5 4,4.96157056080646 3.60981935596774,4.84775906502257 3.23463313526982,4.66293922460509 2.8888595339608,4.41421356237309 2.58578643762691,4.1111404660392 2.33706077539491,3.76536686473018 2.15224093497743,3.39018064403226 2.03842943919354,3 2,2.60981935596774 2.03842943919354,2.23463313526982 2.15224093497743,1.8888595339608 2.33706077539491,1.58578643762691 2.58578643762691,1.33706077539491 2.8888595339608,1.15224093497743 3.23463313526982,1.03842943919354 3.60981935596774,1 4))
以下 SQL 返回输入点几何体的缓冲区,该缓冲区大致为一个圆。由于该命令指定 3 作为每个四分之一圆的区段数,因此该函数使用三个区段表示约四分之一圆。
SELECT ST_AsEwkt(ST_Buffer(ST_GeomFromText('POINT(3 4)'), 2, 3));
st_asewkt
POLYGON((1 4,1.26794919243112 5,2 5.73205080756888,3 6,4 5.73205080756888,4.73205080756888 5,5 4,4.73205080756888 3,4 2.26794919243112,3 2,2 2.26794919243112,1.26794919243112 3,1 4))