Replaces a point in a LineString at the specified index position.
Syntax
geometry ST_SetPoint(geometry linestring, integer zerobasedposition, geometry point);Parameters
| Parameter | Type | Description |
|---|---|---|
linestring | geometry | The LineString geometry to modify. |
zerobasedposition | integer | The zero-based index of the point to replace. Use a negative value to count from the end: -1 refers to the last point. |
point | geometry | The replacement point geometry. |
Usage notes
Indexes are zero-based: the first point is at index
0.Negative indexes count backward from the end:
-1refers 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)该文章对您有帮助吗?