Name

ST_SetPoint — Remplacer le point d'une ligne par un point donné.

Synopsis

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

Description

Remplace le point N de la ligne par le point donné. L'index est basé sur 0. Les index négatifs sont comptés à rebours, de sorte que -1 est le dernier point. Cette fonction est particulièrement utile dans les triggers lorsqu'il s'agit de maintenir la relation entre les articulations lorsqu'un sommet se déplace.

Disponibilité : 1.1.0

Mise à jour 2.3.0 : indexation négative

Cette fonction prend en charge la 3D et ne supprime pas l'indice z.

Exemples

--Change first point in line string from -1 3 to -1 1
SELECT ST_AsText(ST_SetPoint('LINESTRING(-1 2,-1 3)', 0, 'POINT(-1 1)'));
           st_astext
-----------------------
 LINESTRING(-1 1,-1 3)

---Change last point in a line string (lets play with 3d linestring this time)
SELECT ST_AsEWKT(ST_SetPoint(foo.geom, ST_NumPoints(foo.geom) - 1, ST_GeomFromEWKT('POINT(-1 1 3)')))
FROM (SELECT ST_GeomFromEWKT('LINESTRING(-1 2 3,-1 3 4, 5 6 7)') As geom) As foo;
           st_asewkt
-----------------------
LINESTRING(-1 2 3,-1 3 4,-1 1 3)

SELECT ST_AsText(ST_SetPoint(g, -3, p))
FROM ST_GEomFromText('LINESTRING(0 0, 1 1, 2 2, 3 3, 4 4)') AS g
        , ST_PointN(g,1) as p;
           st_astext
-----------------------
LINESTRING(0 0,1 1,0 0,3 3,4 4)

                        

Voir aussi

ST_AddPoint, ST_NPoints, ST_NumPoints, ST_PointN, ST_RemovePoint