名称

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

大纲

geometry ST_ShortestLine(geometry geom1, geometry geom2);

geography ST_ShortestLine(geography geom1, geography geom2, boolean use_spheroid = true);

描述

返回两个几何图形之间的二维最短线。 返回的线从 geom1 开始,到 geom2 结束。 如果geom1geom2相交,结果是一条起点和终点位于交点的线。 线的长度与 g1 和 g2 的 ST_Distance 返回的长度相同。

增强:3.4.0 - 支持地理。

可用性:1.1.0

示例

Shortest line between a Point and a LineString.

Code
SELECT ST_ShortestLine(
        'POINT (160 40)',
        'LINESTRING (10 30,50 50,30 110,70 90,180 140,130 190)') As sline;
栅格输出
LINESTRING(160 40,125.75342465753425 115.34246575342466)
Figure
Geometry figure for visual-st-shortestline-01

Shortest line between polygons.

Code
SELECT ST_ShortestLine(
         'POLYGON ((190 150,20 10,160 70,190 150))',
         ST_Buffer('POINT(80 160)', 30)
                  ) AS llinewkt;
栅格输出
LINESTRING(131.59149149528952 101.89887534906195,101.21320343559643 138.78679656440357)
Figure
Geometry figure for visual-st-shortestline-02