제목

ST_MakeLine — 포인트, 멀티포인트 또는 라인 도형으로부터 라인스트링을 생성합니다.

요약

geometry ST_MakeLine(geometry geom1, geometry geom2);

geometry ST_MakeLine(geometry[] geoms_array);

geometry ST_MakeLine(geometry set geoms);

설명

Creates a LineString containing the points of Point, MultiPoint, or LineString geometries. Other geometry types cause an error.

Variant 1: accepts two input geometries

Variant 2: accepts an array of geometries

Variant 3: aggregate function accepting a rowset of geometries. To ensure the order of the input geometries use ORDER BY in the function call, or a subquery with an ORDER BY clause.

Repeated nodes at the beginning of input LineStrings are collapsed to a single point. Repeated points in Point and MultiPoint inputs are not collapsed. Components of MultiLineString are handled in the order they appear in the collection. ST_RemoveRepeatedPoints can be used to collapse repeated points from the output LineString.

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

Availability: 3.7.0 - Support for MultiLineString input elements was introduced

2.0.0 버전부터 라인스트링 구성 요소 입력을 지원하기 시작했습니다.

2.0.0 버전부터 라인스트링 구성 요소 입력을 지원하기 시작했습니다.

1.4.0 버전부터 사용할 수 있습니다. 이 버전부터 ST_MakeLine가 도형 배열을 입력받을 수 있습니다. 더 많은 포인트를 더 빨리 처리하기 위해 ST_MakeLine 합산 함수를 개선했습니다.

예시

Two-input variant.

Create a line composed of two points.

Code
SELECT ST_MakeLine(ST_Point(1, 2), ST_Point(3, 4));
래스터 출력
LINESTRING(1 2,3 4)
Figure
Geometry figure for visual-st-makeline-01

주어진 3D 포인트 도형 2개로 정의되는 BOX3D를 생성합니다.

Code
SELECT ST_MakeLine(ST_MakePoint(1, 2, 3), ST_MakePoint(3, 4, 5));
래스터 출력
LINESTRING(1 2 3,3 4 5)
Figure
Geometry figure for visual-st-makeline-02

포인트, 멀티포인트 또는 라인 도형으로부터 라인스트링을 생성합니다.

Code
SELECT ST_MakeLine('LINESTRING(0 0,1 1)', 'LINESTRING(2 2,3 3)');
래스터 출력
LINESTRING(0 0,1 1,2 2,3 3)
Figure
Geometry figure for visual-st-makeline-03

Array variant.

Create a line from an array formed by a subquery with ordering.

Code
SELECT ST_MakeLine(ARRAY(SELECT ST_Centroid(geom) FROM visit_locations ORDER BY visit_time));

Create a 3D line from an array of 3D points

Code
SELECT ST_MakeLine(ARRAY[ST_MakePoint(1, 2, 3), ST_MakePoint(3, 4, 5), ST_MakePoint(6, 6, 6)]);
래스터 출력
LINESTRING(1 2 3,3 4 5,6 6 6)
Figure
Geometry figure for visual-st-makeline-04

Aggregate variant.

이 예시는 GPS 포인트 배열을 입력받아, 도형 항목이 이동 순서대로의 GPS 포인트들로 이루어진 라인스트링인 GPS 이동 하나당 한 개의 레코드를 생성합니다.

Using aggregate ORDER BY provides a correctly-ordered LineString.

Code
SELECT gps.track_id, ST_MakeLine(gps.geom ORDER BY gps_time) AS geom
FROM gps_points AS gps
GROUP BY gps.track_id;

When ordering within the aggregate is not possible, ordering in a subquery can be used. However, sometimes the query plan may not respect the order of the subquery.

Code
SELECT gps.track_id, ST_MakeLine(gps.geom) AS geom
FROM (
  SELECT track_id, gps_time, geom
  FROM gps_points
  ORDER BY track_id, gps_time
) AS gps
GROUP BY gps.track_id;