ST_SetPoint
What is ST_SetPoint?
ST_SetPoint replaces the vertex at a given zero-based index of a LineString with a supplied point. The total vertex count does not change.
ST_SetPoint(geometry linestring, integer zerobased_index, geometry point) → geometryThe input must be a LineString and the index must be in range.
When would you use ST_SetPoint?
Use ST_SetPoint to correct an individual bad coordinate — fixing a misplaced endpoint of a street centreline, moving a pipeline control vertex to match as-built data, or nudging a GPS track fix to the nearest road. It is the targeted complement to bulk operations like ST_Translate or ST_Affine.
In data-quality pipelines, ST_SetPoint is often driven from a reference table of known corrections that specify feature id, vertex index, and desired coordinate.
FAQs
Does ST_SetPoint add or remove vertices?
No. Only the existing vertex at the given index is replaced. Use ST_AddPoint to insert or ST_RemovePoint to delete.
What if the index is out of range?
PostGIS raises an "Invalid offset" error. Always check ST_NPoints(geom) before calling.
Does ST_SetPoint work on Polygons?
No. Only LineStrings. For polygon rings, extract the ring, set the point, and rebuild with ST_MakePolygon.
Does it preserve Z and M?
The replacement point's Z and M ordinates are copied onto the LineString's vertex. Make sure the point matches the line's dimensionality or Z/M may be lost.