Name

ST_MakeLine — Creates a Linestring from point, multipoint, or line geometries.

Synopsis

geometry ST_MakeLine(geometry set geoms);

geometry ST_MakeLine(geometry geom1, geometry geom2);

geometry ST_MakeLine(geometry[] geoms_array);

説明

ST_MakeLine comes in 3 forms: a spatial aggregate that takes rows of point, multipoint, or line geometries and returns a line string, a function that takes an array of point, multipoint, or line, and a regular function that takes two point, multipoint, or line geometries. You might want to use a subselect to order points before feeding them to the aggregate version of this function.

Inputs other than point, multipoint, or lines are ignored.

When adding line components common nodes at the beginning of lines are removed from the output. Common nodes in point and multipoint inputs are not removed.

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

Availability: 2.3.0 - Support for multipoint input elements was introduced

Availability: 2.0.0 - ラインストリング入力要素が導入されました。

Availability: 1.4.0 - ST_MakeLine(geomarray)が導入されました。ST_MakeLine集約関数はより多くのポイントをより早く扱うための強化が施されています。

例: 空間集計版

この例では、GPS位置の順列を取り、ジオメトリフィールドがGPSポイントからなるラインストリングで行程順になるよう、行程ごとに一つのレコードを生成します。

-- For pre-PostgreSQL 9.0 - this usually works,
-- but the planner may on occasion choose not to respect the order of the subquery
SELECT gps.gps_track, ST_MakeLine(gps.the_geom) As newgeom
        FROM (SELECT gps_track,gps_time, the_geom
                        FROM gps_points ORDER BY gps_track, gps_time) As gps
        GROUP BY gps.gps_track;
-- If you are using PostgreSQL 9.0+
-- (you can use the new ORDER BY support for aggregates)
-- this is a guaranteed way to get a correctly ordered linestring
-- Your order by part can order by more than one column if needed
SELECT gps.gps_track, ST_MakeLine(gps.the_geom ORDER BY gps_time) As newgeom
        FROM gps_points As gps
        GROUP BY gps.gps_track;

例: 非空間集計版

一つ目の例は二つのポイントからなる使い捨てのラインストリングです。二つ目は、ユーザが描いた二つのポイントからラインストリングを生成しています。三つ目は、二つの3次元ポイントを接続した使い捨ての3次元ラインを生成しています。

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

SELECT userpoints.id, ST_MakeLine(startpoint, endpoint) As drawn_line
        FROM userpoints ;

SELECT ST_AsEWKT(ST_MakeLine(ST_MakePoint(1,2,3), ST_MakePoint(3,4,5)));
                st_asewkt
-------------------------
 LINESTRING(1 2 3,3 4 5)
                        

例: 配列使用版

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

-- 三つの3次元ポイントから3次元ラインを生成
SELECT ST_AsEWKT(ST_MakeLine(ARRAY[ST_MakePoint(1,2,3),
                                ST_MakePoint(3,4,5), ST_MakePoint(6,6,6)]));
                st_asewkt
-------------------------
LINESTRING(1 2 3,3 4 5,6 6 6)
                        

関連情報

ST_AsEWKT, ST_AsText, ST_GeomFromText, ST_MakePoint