名前

ST_AddPoint — Add a point to a LineString.

概要

geometry ST_AddPoint(geometry linestring, geometry point);

geometry ST_AddPoint(geometry linestring, geometry point, integer position);

説明

ラインストリングに対して指定した<position> (0はじまり)の前にポイントを追加します。第3引数に-1を指定すると末尾に追加できます。

Availability: 1.1.0

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

-- テーブル内の全てのラインストリングのうち閉じていないものについて、
-- 最初のポイントを末尾に追加することで、
-- 全てのラインストリングが閉じていることを保証します
                UPDATE sometable
                SET the_geom = ST_AddPoint(the_geom, ST_StartPoint(the_geom))
                FROM sometable
                WHERE ST_IsClosed(the_geom) = false;

                --Adding point to a 3-d line
                SELECT ST_AsEWKT(ST_AddPoint(ST_GeomFromEWKT('LINESTRING(0 0 1, 1 1 1)'), ST_MakePoint(1, 2, 3)));

                --result
                st_asewkt
                ----------
                LINESTRING(0 0 1,1 1 1,1 2 3)
                        

関連情報

ST_RemovePoint, ST_SetPoint