Skip to main content
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. ST_ShortestLine between two geometries

Signatures

ST_ShortestLine(geom1: Geometry, geom2: Geometry)

Parameters

geom1
Geometry
required
The geometry where the shortest line starts.
geom2
Geometry
required
The geometry where the shortest line ends.

Return type

The shortest LineString connecting the two geometries.

Example

ST_ShortestLine from a point to a point
SELECT ST_ShortestLine(
        ST_GeomFromText('POINT (0 0)'),
        ST_GeomFromText('POINT (3 4)')
)
LINESTRING (0 0, 3 4)
Point to LineString: ST_ShortestLine from a point to a linestring
SELECT ST_ShortestLine(
        ST_GeomFromText('POINT (0 1)'),
        ST_GeomFromText('LINESTRING (0 0, 1 0, 2 0, 3 0, 4 0, 5 0)')
)
LINESTRING (0 1, 0 0)