PostGIS

ST_3DLongestLine

Prev

8.12. Measurement Functions

Next

Name

ST_3DLongestLine — Returns the 3D longest line between two geometries

Synopsis

geometry +`*`+ST_3DLongestLine*(`geometry `g1, geometry g2`)`;

Description

Returns the 3-dimensional longest line between two geometries. The function returns the first longest line if more than one. The line returned starts in g1 and ends in g2. The 3D length of the line is equal to the distance returned by ST_3DMaxDistance.

Availability: 2.0.0

Changed: 2.2.0 - if 2 2D geometries are input, a 2D point is returned (instead of old behavior assuming 0 for missing Z). In case of 2D and 3D, Z is no longer assumed to be 0 for missing Z.

check This function supports 3d and will not drop the z-index.

check This function supports Polyhedral surfaces.

Examples

linestring and point — both 3d and 2d longest line

SELECT ST_AsEWKT(ST_3DLongestLine(line,pt)) AS lol3d_line_pt,
        ST_AsEWKT(ST_LongestLine(line,pt)) As lol2d_line_pt
    FROM (SELECT 'POINT(100 100 30)'::geometry As pt,
            'LINESTRING (20 80 20, 98 190 1, 110 180 3, 50 75 1000)'::geometry As line
        ) As foo;


           lol3d_line_pt

lol2d_line_pt -----------------------------------+---------------------------- LINESTRING(50 75 1000,100 100 30)

LINESTRING(98 190,100 100)

----

linestring and multipoint — both 3d and 2d longest line

SELECT ST_AsEWKT(ST_3DLongestLine(line,pt)) AS lol3d_line_pt,
        ST_AsEWKT(ST_LongestLine(line,pt)) As lol2d_line_pt
    FROM (SELECT 'MULTIPOINT(100 100 30, 50 74 1000)'::geometry As pt,
            'LINESTRING (20 80 20, 98 190 1, 110 180 3, 50 75 900)'::geometry As line
        ) As foo;


          lol3d_line_pt

lol2d_line_pt ---------------------------------+-------------------------- LINESTRING(98 190 1,50 74 1000)

LINESTRING(98 190,50 74)

----

MultiLineString and Polygon both 3d and 2d longest line

SELECT ST_AsEWKT(ST_3DLongestLine(poly, mline)) As lol3d,
    ST_AsEWKT(ST_LongestLine(poly, mline)) As lol2d
        FROM (SELECT  ST_GeomFromEWKT('POLYGON((175 150 5, 20 40 5, 35 45 5, 50 60 5, 100 100 5, 175 150 5))') As poly,
                ST_GeomFromEWKT('MULTILINESTRING((175 155 2, 20 40 20, 50 60 -2, 125 100 1, 175 155 1),
                (1 10 2, 5 20 1))') As mline ) As foo;
            lol3d

lol2d ------------------------------+-------------------------- LINESTRING(175 150 5,1 10 2)

LINESTRING(175 150,1 10)

----