ST_SetPoint

更新时间:
复制 MD 格式

Replaces the point at a specified zero-based index in a LineString with a given point.

Syntax

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

Parameters

ParameterDescription
linestringThe LineString geometry whose point you want to replace.
zerobasedpositionThe index of the point to replace. Indexes start at 0. Negative indexes count from the end: -1 is the last point, -2 is the second-to-last, and so on.
pointThe replacement point.

Usage notes

  • ST_SetPoint preserves Z coordinates and supports 3D geometry.

  • ST_SetPoint is useful in triggers to maintain joint relationships when a vertex moves.

Examples

Replace the first point (index 0)

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)