ST_MakeLine

更新时间:
复制 MD 格式

Constructs a LineString geometry from Point, MultiPoint, or LineString geometries.

Syntax

geometry ST_MakeLine(geometry set geoms)
geometry ST_MakeLine(geometry geom1, geometry geom2)
geometry ST_MakeLine(geometry[] geomsArray)

Parameters

ParameterDescription
geomsThe geometry objects that you want to specify.
geom1The first geometry object.
geom2The second geometry object.
geomsArrayAn array of geometry objects.

Usage notes

  • Unsupported input types: Only Point, MultiPoint, and LineString geometries are accepted. Any other geometry type is silently ignored.

  • Common nodes: When a LineString object is added, this function deletes the common nodes at the beginning of lines. If you specify points or MultiPoints, this function does not delete the common nodes at the beginning of points or MultiPoints.

  • 3D support: 3D geometries are fully supported. The Z coordinate of input geometries is preserved in the output.

Examples

Two-input variant

Construct a LineString from two points.

SELECT ST_AsText(ST_MakeLine(ST_MakePoint(1,2), ST_MakePoint(3,4)));

Output:

      st_astext
---------------------
 LINESTRING(1 2,3 4)
(1 row)

Array variant

Construct a LineString from an array of points.

SELECT ST_AsText(ST_MakeLine(ARRAY[ST_MakePoint(1,2), ST_MakePoint(3,4), ST_MakePoint(5,6)]));

Output:

        st_astext
-------------------------
 LINESTRING(1 2,3 4,5 6)
(1 row)

3D variant

Construct a 3D LineString. The Z coordinate is preserved in the output.

SELECT ST_AsText(ST_MakeLine(ST_MakePoint(1,2,3), ST_MakePoint(4,5,6)));

Output:

         st_astext
----------------------------
 LINESTRING Z (1 2 3,4 5 6)
(1 row)