Returns the shortest LineString between two geometries. The line starts on geom1 and ends on geom2. If either geometry is empty, the function returns null.
Signatures
ST_ShortestLine(geom1: Geometry, geom2: Geometry)
Parameters
The geometry where the shortest line starts.
The geometry where the shortest line ends.
Return type
The shortest LineString connecting the two geometries.
Example
SELECT ST_ShortestLine(
ST_GeomFromText('POINT (0 0)'),
ST_GeomFromText('POINT (3 4)')
)
Point to LineString:
SELECT ST_ShortestLine(
ST_GeomFromText('POINT (0 1)'),
ST_GeomFromText('LINESTRING (0 0, 1 0, 2 0, 3 0, 4 0, 5 0)')
)