Nombre

ST_SetPoint — Reemplace el punto de una cadena de línea con un punto dado.

Sinopsis

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

Descripción

Reemplace el punto N de una cadena de línea con el punto dado. El índice comineza en 0. El índice negativo se cuenta hacia atrás, por lo que -1 es el último punto. Esto es especialmente útil en los disparadores cuando se trata de mantener la relación de las articulaciones cuando un vértice se mueve.

Disponibilidad: 1.1.0

Actualizado 2.3.0: indexación negativa

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

Ejemplos

Change first point in line string from -1 3 to -1 1.

Code
SELECT ST_SetPoint('LINESTRING(-1 2,-1 3)', 0, 'POINT(-1 1)');
Output
LINESTRING(-1 1,-1 3)
Figure
Geometry figure for visual-st-setpoint-01

Change last point in a line string (let's play with 3D linestring this time)

Code
SELECT ST_SetPoint(foo.geom, ST_NumPoints(foo.geom) - 1, 'POINT(-1 1 3)')
FROM (SELECT 'LINESTRING(-1 2 3,-1 3 4,5 6 7)'::geometry As geom) As foo;
Output
LINESTRING(-1 2 3,-1 3 4,-1 1 3)
Figure
Geometry figure for visual-st-setpoint-02
Code
SELECT ST_SetPoint(g, -3, p)
FROM ST_GeomFromText('LINESTRING(0 0,1 1,2 2,3 3,4 4)') AS g
    CROSS JOIN ST_PointN(g, 1) as p;
Output
LINESTRING(0 0,1 1,0 0,3 3,4 4)
Figure
Geometry figure for visual-st-setpoint-03