名前

ST_SetPoint — ラインストリングのN番目を与えられたポイントに置き換えます。インデクスは0はじまりです。

概要

geometry ST_SetPoint(geometry linestring, integer zerobasedposition, geometry point);

説明

ラインストリングのN番目を与えられたポイントに置き換えます。インデクスは0はじまりです。これは、頂点が一つ動いた時に接続のリレーションシップを維持しようとする場合のトリガに特に便利です。

Availability: 1.1.0

Updated 2.3.0 : negative indexing

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

-- ラインストリング先頭のポイントを-1 3から-1 1に変更
SELECT ST_AsText(ST_SetPoint('LINESTRING(-1 2,-1 3)', 0, 'POINT(-1 1)'));
           st_astext
-----------------------
 LINESTRING(-1 1,-1 3)

-- ラインストリング末尾のポイントを変更 (3次元ラインストリングでやってみます)
SELECT ST_AsEWKT(ST_SetPoint(foo.the_geom, ST_NumPoints(foo.the_geom) - 1, ST_GeomFromEWKT('POINT(-1 1 3)')))
FROM (SELECT ST_GeomFromEWKT('LINESTRING(-1 2 3,-1 3 4, 5 6 7)') As the_geom) As foo;
           st_asewkt
-----------------------
LINESTRING(-1 2 3,-1 3 4,-1 1 3)

                        

関連情報

ST_AddPoint, ST_NPoints, ST_NumPoints, ST_PointN, ST_RemovePoint