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 - 如果输入两个 2D 几何体,则返回一个 2D 点(而不是假设缺失 Z 为 0 的旧行为)。在 2D 和 3D 的情况下,不再假设缺失 Z 的 Z 为 0。
此函数支持 3d,不会丢弃 z 索引。
此函数支持多面体表面。
线串和点 -- 3d 和 2d 最短线 SELECT ST_AsEWKT(ST_3DShortestLine(line,pt)) AS shl3d_line_pt, ST_AsEWKT(ST_ShortestLine(line,pt)) As shl2d_line_pt FROM (SELECT 'POINT(100 100 30)'::geometry As pt, 'LINESTRING (20 80 20, 98 190 1, 110 180 3, 50 75 1000)'::geometry As line ) As foo; shl3d_line_pt | shl2d_line_pt ----------------------------------------------------------------------------+------------------------------------------------------ LINESTRING(54.6993798867619 128.935022917228 11.5475869506606,100 100 30) | LINESTRING(73.0769230769231 115.384615384615,100 100)
|
线串和多点 -- 3d 和 2d 最短线 SELECT ST_AsEWKT(ST_3DShortestLine(line,pt)) AS shl3d_line_pt, ST_AsEWKT(ST_ShortestLine(line,pt)) As shl2d_line_pt FROM (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 ) As foo; shl3d_line_pt | shl2d_line_pt ---------------------------------------------------------------------------+------------------------ LINESTRING(54.6993798867619 128.935022917228 11.5475869506606,100 100 30) | LINESTRING(50 75,50 74)
|
多线串和多边形 -- 3d 和 2d 最短线 SELECT ST_AsEWKT(ST_3DShortestLine(poly, mline)) As shl3d, ST_AsEWKT(ST_ShortestLine(poly, mline)) As shl2d FROM (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 ) As foo; shl3d | shl2d ---------------------------------------------------------------------------------------------------+------------------------ LINESTRING(39.993580415989 54.1889925532825 5,40.4078575708294 53.6052383805529 5.03423778139177) | LINESTRING(20 40,20 40)
|