Categories:

Geospatial Functions

# ST_MAKELINE¶

Constructs a GEOGRAPHY object that represents a line connecting the points in the input objects.

TO_GEOGRAPHY

## Syntax¶

ST_MAKELINE( <geography_expression_1> , <geography_expression_2> )


## Arguments¶

geography_expression_1

A GEOGRAPHY object containing the points to connect. This object must be a Point, MultiPoint, or LineString.

geography_expression_2

A GEOGRAPHY object containing the points to connect. This object must be a Point, MultiPoint, or LineString.

## Returns¶

The function returns a value of type GEOGRAPHY. The value is a LineString that connects all of the points specified by the input GEOGRAPHY objects.

## Usage Notes¶

• If an input GEOGRAPHY object contains multiple points, ST_MAKELINE connects all of the points specified in the object.

• ST_MAKELINE connects the points in the order in which they are specified in the input.

## Examples¶

The examples in this section display output in WKT format:

alter session set GEOGRAPHY_OUTPUT_FORMAT='WKT';


The following example uses ST_MAKELINE to construct a LineString that connects two Points:

SELECT ST_MAKELINE(
TO_GEOGRAPHY('POINT(37.0 45.0)'),
TO_GEOGRAPHY('POINT(38.5 46.5)')
) AS line_between_two_points;
+-----------------------------+
| LINE_BETWEEN_TWO_POINTS     |
|-----------------------------|
| LINESTRING(37 45,38.5 46.5) |
+-----------------------------+


The following example constructs a LineString that connects a Point with the points in a MultiPoint:

SELECT ST_MAKELINE(
TO_GEOGRAPHY('POINT(-122.306067 37.55412)'),
TO_GEOGRAPHY('MULTIPOINT((-122.32328 37.561801), (-122.325879 37.586852))')
) AS line_between_point_and_multipoint;
+-----------------------------------------------------------------------------+
| LINE_BETWEEN_POINT_AND_MULTIPOINT                                           |
|-----------------------------------------------------------------------------|
| LINESTRING(-122.306067 37.55412,-122.32328 37.561801,-122.325879 37.586852) |
+-----------------------------------------------------------------------------+


As demonstrated by the output of the example, ST_MAKELINE connects the points in the order in which they are specified in the input.

The following example constructs a LineString that connects the points in a MultiPoint with another LineString:

SELECT ST_MAKELINE(
TO_GEOGRAPHY('MULTIPOINT((-122.32328 37.561801), (-122.325879 37.586852))'),
TO_GEOGRAPHY('LINESTRING(-122.306067 37.55412, -122.496691 37.495627)')
) AS line_between_multipoint_and_linestring;
+---------------------------------------------------------------------------------------------------+
| LINE_BETWEEN_MULTIPOINT_AND_LINESTRING                                                            |
|---------------------------------------------------------------------------------------------------|
| LINESTRING(-122.32328 37.561801,-122.325879 37.586852,-122.306067 37.55412,-122.496691 37.495627) |
+---------------------------------------------------------------------------------------------------+