Skip to content
🌵SedonaDB (Rust) 0.3.0 is out now, featuring larger-than-memory spatial joins, and row-level CRS!

ST_ShortestLine

Introduction: 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

Format: ST_ShortestLine(geom1: Geometry, geom2: Geometry)

Return type: Geometry

SQL Example:

ST_ShortestLine Point to Point

SELECT ST_ShortestLine(
        ST_GeomFromText('POINT (0 0)'),
        ST_GeomFromText('POINT (3 4)')
)

Output:

LINESTRING (0 0, 3 4)

SQL Example:

ST_ShortestLine 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)')
)

Output:

LINESTRING (0 1, 0 0)