Name

ST_SetPoint — Replaces the Nth Point of a Geometry for a new Point. N index starts at 0.

Synopsis

geometry ST_SetPoint(bytea Geometry, integer N, bytea Point);

Alias

SetPoint

Description

Replaces the Nth Point of a Geometry for a new Point. N index starts at 0.

If the N index is out of range, the incoming geometry is returned unchanged.

Coordinate Dimensions
2D3DM
Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006)SQL-MM Part 3
----

Examples

SELECT ST_AsEWKT(Line) as original,
       ST_AsEWKT(ST_SetPoint(Line,0,Point)) as NewPoint0,
       ST_AsEWKT(ST_SetPoint(Line,1,Point)) as NewPoint1 
FROM (SELECT ST_GeomFromEWKT('LINESTRING (0 0, 10 10, 20 10)') as Line, ST_GeomFromEWKT('POINT (-5 5)') as Point) as foo;

            original            |            newpoint0            |           newpoint1
--------------------------------+---------------------------------+-------------------------------
 LINESTRING (0 0, 10 10, 20 10) | LINESTRING (-5 5, 10 10, 20 10) | LINESTRING (0 0, -5 5, 20 10)


SELECT ST_AsEWKT(ST_SetPoint(ST_GeomFromEWKT('MULTILINESTRING ((0 0, 10 10, 20 10),(30 30, 40 40, 50 40))'),5,ST_GeomFromEWKT('POINT (-5 5)')));
--Result
MULTILINESTRING ((0 0, 10 10, 20 10), (30 30, 40 40, -5 5)) 

--Polygon
SELECT ST_AsEWKT(ST_SetPoint(ST_GeomFromEWKT('POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))'),2,ST_GeomFromEWKT('POINT (-5 5)')));
--Result
POLYGON ((0 0, 0 10, -5 5, 10 0, 0 0))

--MultiPoint
SELECT ST_AsEWKT(ST_SetPoint(ST_GeomFromEWKT('MULTIPOINT (0 0, 0 10, 10 10, 10 0, 0 0)'),0,ST_GeomFromEWKT('POINT (-5 5)')));
                      st_asewkt                      
-----------------------------------------------------
 MULTIPOINT ((-5 5), (0 10), (10 10), (10 0), (0 0))
(1 row)


--N index out of range
SELECT ST_AsEWKT(ST_SetPoint(ST_GeomFromEWKT('LINESTRING (0 0, 10 10, 20 10)'),5,ST_GeomFromEWKT('POINT (-5 5)')));
--Result
LINESTRING (0 0, 10 10, 20 10)

Related functions

ST_AddPoint