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
| Parameter | Description |
|---|---|
linestring | The LineString geometry whose point you want to replace. |
zerobasedposition | The 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. |
point | The 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)该文章对您有帮助吗?