ST_OffsetCurve — 返回距输入线给定距离和方向的偏移线。
geometry ST_OffsetCurve(geometry line, float signed_distance, text style_parameters='');
返回距输入线给定距离和方向的偏移线。 返回几何图形的所有点与输入几何图形的距离不超过给定距离。 对于计算围绕中心线的平行线很有用。
对于正距离,偏移位于输入线的左侧并保持相同的方向。 对于负距离,它位于右侧且方向相反。
距离单位以空间参考系的单位来测量。
请注意,对于某些拼图形状的输入几何图形,输出可能是 MULTILINESTRING 或 EMPTY。
可选的第三个参数允许指定空白分隔的键=值对的列表来调整操作,如下所示:
'quad_segs=#' :用于近似四分之一圆的线段数(默认为 8)。
'join=round|mitre|bevel' :连接样式(默认为“round”)。 “mitre”也被认为是“mitre”的同义词。
'mitre_limit=#.#' :斜接比率限制(仅影响斜接连接样式)。 “miter_limit”也被接受为“mitre_limit”的同义词。
这个函数是由 GEOS 模块执行的。
在 GEOS 3.11 中,行为发生了变化,因此在正负偏移下,偏移曲线与输入线具有相同的方向。
可用性:2.0
增强:2.5 - 添加了对 GEOMETRYCOLLECTION 和 MULTILINESTRING 的支持
|
|
|
此函数忽略 Z 维度。 即使在 3D 几何体上使用时,它也始终给出 2D 结果。 |
Compute an open buffer around roads.
SELECT ST_Union(
ST_OffsetCurve(f.geom, f.width/2, 'quad_segs=4 join=round'),
ST_OffsetCurve(f.geom, -f.width/2, 'quad_segs=4 join=round')
) as track
FROM someroadstable;
Offset 15 units with quad_segs=4 join=round.
SELECT ST_OffsetCurve(
ST_GeomFromText('LINESTRING(164 16,144 16,124 16,104 16,84 16,64 16,
44 16,24 16,20 16,18 16,17 17,
16 18,16 20,16 40,16 60,16 80,16 100,
16 120,16 140,16 160,16 180,16 195)'),
15, 'quad_segs=4 join=round');
LINESTRING(164 1,18 1,15.073645169758077 1.288220793951544,
12.259748514523654 2.141807012330698,9.66644650470597 3.527955815461818,
7.393398282201788 5.393398282201788,5.393398282201788 7.393398282201788,
3.527955815461818 9.66644650470597,2.141807012330696 12.259748514523654,
1.288220793951544 15.073645169758075,1 18,1 195)
Offset -15 units with quad_segs=4 join=round.
SELECT ST_OffsetCurve(
geom,
-15,
'quad_segs=4 join=round') As notsocurvy
FROM ST_GeomFromText('LINESTRING(164 16,144 16,124 16,104 16,84 16,64 16,
44 16,24 16,20 16,18 16,17 17,
16 18,16 20,16 40,16 60,16 80,16 100,
16 120,16 140,16 160,16 180,16 195)') As geom;
LINESTRING(164 31,31 31,31 195)
Apply two negative offsets to obtain a smoother curve; the distances combine to -45 units.
SELECT ST_OffsetCurve(
ST_OffsetCurve(
geom,
-30,
'quad_segs=4 join=round'),
-15,
'quad_segs=4 join=round') As morecurvy
FROM ST_GeomFromText('LINESTRING(164 16,144 16,124 16,104 16,84 16,64 16,
44 16,24 16,20 16,18 16,17 17,
16 18,16 20,16 40,16 60,16 80,16 100,
16 120,16 140,16 160,16 180,16 195)') As geom;
LINESTRING(164 61,61 61,61 195)
Collect the positive offset and the double-offset to produce parallel curves.
SELECT ST_Collect(
ST_OffsetCurve(geom, 15, 'quad_segs=4 join=round'),
ST_OffsetCurve(
ST_OffsetCurve(
geom,
-30,
'quad_segs=4 join=round'),
-15,
'quad_segs=4 join=round')
) As parallel_curves
FROM ST_GeomFromText('LINESTRING(164 16,144 16,124 16,104 16,84 16,64 16,
44 16,24 16,20 16,18 16,17 17,
16 18,16 20,16 40,16 60,16 80,16 100,
16 120,16 140,16 160,16 180,16 195)') As geom;
MULTILINESTRING((164 1,18 1,15.073645169758077 1.288220793951544, 12.259748514523654 2.141807012330698,9.66644650470597 3.527955815461818, 7.393398282201788 5.393398282201788,5.393398282201788 7.393398282201788, 3.527955815461818 9.66644650470597,2.141807012330696 12.259748514523654, 1.288220793951544 15.073645169758075,1 18,1 195),(164 61,61 61,61 195))
Offset 15 units with a bevel join.
SELECT ST_OffsetCurve(
ST_GeomFromText('LINESTRING(164 16,144 16,124 16,104 16,84 16,64 16,
44 16,24 16,20 16,18 16,17 17,
16 18,16 20,16 40,16 60,16 80,16 100,
16 120,16 140,16 160,16 180,16 195)'),
15, 'quad_segs=4 join=bevel');
LINESTRING(164 1,18 1,7.393398282201788 5.393398282201788,
5.393398282201788 7.393398282201788,1 18,1 195)
Collect offsets on both sides using a mitre join and a mitre limit of 2.2.
SELECT ST_Collect(
ST_OffsetCurve(geom, 15, 'quad_segs=4 join=mitre mitre_limit=2.2'),
ST_OffsetCurve(geom, -15, 'quad_segs=4 join=mitre mitre_limit=2.2')
)
FROM ST_GeomFromText('LINESTRING(164 16,144 16,124 16,104 16,84 16,64 16,
44 16,24 16,20 16,18 16,17 17,
16 18,16 20,16 40,16 60,16 80,16 100,
16 120,16 140,16 160,16 180,16 195)') As geom;
MULTILINESTRING((164 1,11.786796564403577 1,1 11.786796564403577,1 195),
(164 31,31 31,31 195))