1

I have a linestring on my postgis. and I want to add a new point linestring. I mean I want to update my linestring? how can ı do this?

UPDATE roads SET geom = ST_AddPoint(geom, 'POINT(0,0)') WHERE id =9; 

1 Answer 1

5

You need to use a geometry object, rather than just the text representation.

UPDATE roads SET geom = ST_AddPoint(geom, ST_MakePoint(0,0)) WHERE id = 9;

That will work if you want to add the point to the end of the line. If you want to add it as the nth vertex, you would use the optional third parameter. For example, if you want to add your point as the third vertex:

UPDATE roads SET geom = ST_AddPoint(geom, ST_MakePoint(0,0), 2) WHERE id = 9;

Note that the position parameter (2 above) is a zero-based index. So to add a new start point, you would use 0.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.