名称

ST_3DShortestLine — 返回两个几何图形之间的 3D 最短线

大纲

geometry ST_3DShortestLine(geometry g1, geometry g2);

描述

返回两个几何图形之间的 3 维最短线。 如果函数找到多个最短线,则该函数将仅返回第一个最短线。 如果 g1 和 g2 仅相交于一个点,则该函数将返回一条起点和终点均位于该交点的线。 如果 g1 和 g2 与多个点相交,该函数将返回一条起点和终点位于同一点的线,但它可以是任何相交点。 返回的线始终以 g1 开始并以 g2 结束。 此函数返回的线的 3D 长度始终与 ST_3DDistance 返回的 g1 和 g2 相同。

可用性: 2.0.0

更改:2.2.0 - 如果输入 2 个 2D 几何图形,则返回 2D 点(而不是假设缺失 Z 为 0 的旧行为)。 在 2D 和 3D 情况下,对于缺失的 Z,Z 不再被假定为 0。

该函数支持 3d 并且不会丢失 z-index。

该函数支持多面体曲面。

示例

Compare the 3D shortest line to the 2D shortest line for a LineString and a Point.

Code
WITH input AS (
  SELECT 'POINT(100 100 30)'::geometry AS pt,
         'LINESTRING (20 80 20,98 190 1,110 180 3,50 75 1000)'::geometry AS line
)
SELECT ST_3DShortestLine(line, pt) AS shl3d_line_pt,
       ST_ShortestLine(line, pt) AS shl2d_line_pt
FROM input;
栅格输出
-[ RECORD 1 ]--+--------------------------------------------------------------------------------
shl3d_line_pt  | LINESTRING(54.69937988676193 128.93502291722837 11.547586950660556,100 100 30)
shl2d_line_pt  | LINESTRING(73.07692307692307 115.38461538461539,100 100)
Figure
Geometry figure for visual-st-3dshortestline-01

Compare the 3D shortest line to the 2D shortest line for a LineString and a MultiPoint.

Code
WITH input AS (
  SELECT 'MULTIPOINT(100 100 30,50 74 1000)'::geometry AS pt,
         'LINESTRING (20 80 20,98 190 1,110 180 3,50 75 900)'::geometry AS line
)
SELECT ST_3DShortestLine(line, pt) AS shl3d_line_pt,
       ST_ShortestLine(line, pt) AS shl2d_line_pt
FROM input;
栅格输出
-[ RECORD 1 ]--+--------------------------------------------------------------------------------
shl3d_line_pt  | LINESTRING(54.69937988676193 128.93502291722837 11.547586950660556,100 100 30)
shl2d_line_pt  | LINESTRING(50 75,50 74)
Figure
Geometry figure for visual-st-3dshortestline-02

Compare the 3D shortest line to the 2D shortest line for a Polygon and a MultiLineString.

Code
WITH input AS (
  SELECT ST_GeomFromEWKT(
           'POLYGON((175 150 5,20 40 5,35 45 5,50 60 5,100 100 5,175 150 5))'
         ) AS poly,
         ST_GeomFromEWKT(
           'MULTILINESTRING((175 155 2,20 40 20,50 60 -2,125 100 1,175 155 1),
                            (1 10 2,5 20 1))'
         ) AS mline
)
SELECT ST_3DShortestLine(poly, mline) AS shl3d,
       ST_ShortestLine(poly, mline) AS shl2d
FROM input;
栅格输出
-[ RECORD 1 ]--+--------------------------------------------------------------------------------------
shl3d          | LINESTRING(40.45454545454545 53.63636363636364 5,40.45454545454545 53.63636363636364 5)
shl2d          | LINESTRING(20 40,20 40)
Figure
Geometry figure for visual-st-3dshortestline-03