Name

ST_SetPoint — Substitui ponto de uma linestring com um dado ponto.

Synopsis

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

Descrição

Substitui ponto N de linstring com um dado ponto. Index é de base 0. Index negativo são contados atrasados, logo -1 é o último ponto. Isso é especialmente usado em causas tentando manter relações juntas quando um vértice se move.

Disponibilidade: 1.1.0

Atualizado 2.3.0: indexing negativo

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

Exemplos

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)'));
LINESTRING(-1 1,-1 3)

Change last point in a line string (let's 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;
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
        CROSS JOIN ST_PointN(g,1) as p;
LINESTRING(0 0,1 1,0 0,3 3,4 4)