I have MulitLineStrings that may consist of several detached lines like these three:

enter image description here

What I need is to transform it to a LineString. For my use case it would be the best strategy if I could connect the lines with the shortest connection line between each other so that I would get this:

enter image description here

I was thinking of using a combination of ST_Dump() and ST_ShortestLine() but was wondering if there may be another hack to do that.

  • I think you will at first have to group the lines by directionality, this will at least help you fill up the gaps between lines with the same direction. If you know that 1 and 2 "belong together" you could determine the points furthest apart, make a line, and then use something like st_difference to fill up the missing part. Once these are found and you want to connect 3 to the now merged 1+2 you could make all possibly connections and throw away those that intersect with anything but the street (you will have to use OSM for this). Aug 21 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.