Monday 3 February 2020

postgis - How to add vertices to existing linestrings?


If I have


Linestring(1 2, 1 5, 1 9)

and a


Point(1 3)

Is there any function that can merge linestring and point preserving the order so output would be:


Linestring(1 2, 1 3, 1 5, 1 9)

Answer




If the LineString is simply to be subdivided at a position closest to the given Point, you could do what you want with this (splits LineString at closest Point to given Point and remerges the two segements afterwards)


SELECT ST_AsText(
ST_LineMerge(
ST_Union(
ST_Line_Substring(line, 0, ST_Line_Locate_Point(line, point)),
ST_Line_Substring(line, ST_Line_Locate_Point(line, point), 1)
)))
FROM ST_GeomFromText('Linestring(1 2, 1 5, 1 9)') as line,
ST_GeomFromText('Point(1 3)') as point;


However, if your Point is not supposed to be projected on the LineString, this will not work.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...