This topic describes the ST_LongestLine function. This function calculates the line that represents the farthest distance between the points of two 2D geometry objects.

Syntax

geometry  ST_LongestLine(geometry  g1 , geometry  g2);

Parameters

Parameter Description
g1 The first geometry object that you want to specify.
g2 The second geometry object that you want to specify.

Examples

Calculate the line that represents the farthest distance between the points of two 2D geometry objects by using the default parameter settings.
SELECT ST_AsText(ST_LongestLine('POINT(0 0)'::geometry,'LINESTRING(0 0,1 1)'::geometry));
      st_astext
---------------------
 LINESTRING(0 0,1 1)
(1 row)