Name

ST_AddPoint — Adds a point to a LineString before point <position> (0-based index).

Synopsis

geometry ST_AddPoint(geometry linestring, geometry point);

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

Description

Adds a point to a LineString before point <position> (0-based index). Third parameter can be omitted or set to -1 for appending.

Availability: 1.1.0

This function supports 3d and will not drop the z-index.

Examples

		--guarantee all linestrings in a table are closed
		--by adding the start point of each linestring to the end of the line string
		--only for those that are not closed
		UPDATE sometable
		SET the_geom = ST_AddPoint(the_geom, ST_StartPoint(the_geom))
		FROM sometable
		WHERE ST_IsClosed(the_geom) = false;

		--Adding point to a 3-d line
		SELECT ST_AsEWKT(ST_AddPoint(ST_GeomFromEWKT('LINESTRING(0 0 1, 1 1 1)'), ST_MakePoint(1, 2, 3)));

		--result
		st_asewkt
		----------
		LINESTRING(0 0 1,1 1 1,1 2 3)
			

See Also

ST_RemovePoint, ST_SetPoint