ST_AddPoint

更新时间:
复制 MD 格式

Adds a point to a LineString geometry.

Syntax

geometry ST_AddPoint(geometry linestring, geometry point);
geometry ST_AddPoint(geometry linestring, geometry point, integer position);

Parameters

ParameterDescription
linestringThe LineString geometry to modify.
pointThe point to add.
positionThe index at which to insert the point. Indexes start at 0. Set to -1 to append the point to the end of the LineString.

Usage notes

  • Position indexes start at 0.

  • Set position to -1 to append the point to the end of the LineString.

  • Supports 3D geometries. Z coordinates are preserved.

Examples

Append a point to a two-point LineString:

SELECT ST_AsEWKT(ST_AddPoint(ST_GeomFromEWKT('LINESTRING(0 0,0 1)'), ST_MakePoint(1,2)));

Output:

        st_asewkt
-------------------------
 LINESTRING(0 0,0 1,1 2)
(1 row)