ST_3DShortestLine — 二つのジオメトリの3次元の最短ラインを返します。
geometry ST_3DShortestLine(geometry g1, geometry g2);
二つのジオメトリの3次元長が最短となるラインを返します。見つかった最短線が複数ある場合は、最初のもののみ返します。g1とg2が1点のみでインタセクトする場合は、インタセクション点を開始点と終了点とします。g1とg2が1点より多くインタセクトする場合は、同じ点を開始点と終了点としますが、その点は不定です。返されるラインは常にg1側を始点、g2側を終点とします。この関数が返すラインの長さは、常にg1とg2を指定した場合のST_3DDistanceが返す値と同じになります。
Availability: 2.0.0
Changed: 2.2.0 - 二つの2次元ジオメトリが入力である場合には、2次元ポイントが返ります (古い挙動では、存在しないZの値について0を仮定していました)。2次元と3次元の場合には、もはや、存在しないZの値について0を仮定しません。
この関数は3次元に対応し、Z値を削除しません。
この関数は多面体サーフェスに対応しています。
Compare the 3D shortest line to the 2D shortest line for a LineString and a Point.
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;
Compare the 3D shortest line to the 2D shortest line for a LineString and a MultiPoint.
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;
Compare the 3D shortest line to the 2D shortest line for a Polygon and a MultiLineString.
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;