ST_SetPoint

更新时间:
复制 MD 格式

Replaces a point in a LineString at the specified index position.

Syntax

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

Parameters

ParameterTypeDescription
linestringgeometryThe LineString geometry to modify.
zerobasedpositionintegerThe zero-based index of the point to replace. Use a negative value to count from the end: -1 refers to the last point.
pointgeometryThe replacement point geometry.

Usage notes

  • Indexes are zero-based: the first point is at index 0.

  • Negative indexes count backward from the end: -1 refers to the last point.

  • This function is useful in database triggers that maintain joint relationships when a vertex moves.

  • 3D geometries are fully supported. z coordinates are preserved and not dropped.

Examples

Replace the first point of a LineString:

SELECT ST_AsText(ST_SetPoint(ST_GeomFromText('LINESTRING(2 1,1 1)'),0,ST_MakePoint(0,1)));

Output:

      st_astext
---------------------
 LINESTRING(0 1,1 1)
(1 row)