2

I have a path from point A to point B, which I want to double back on itself to create a path from A to B back to A.

It seemed like using ST_LineMerge on the MULTILINESTRING created by ST_Collect from the two LINESTRINGS was the answer, however it doesn't appear to maintain the ordering of the paths supplied in the MULTILINESTRING.

For example in psudosql

ST_LineMerge(
    MULTILINESTRING(
        (Point A, Point B),
        (Point B, Point A)
    )
)

Creates a path B to A to B, as opposed to A to B to A as I would expect based on the LINESTRING order and directions.

How can I reliably join these paths together?

Here is a concrete example...

SELECT ST_AsText(ST_LineMerge(ST_GeomFromText('MULTILINESTRING Z ((151.2569403 -33.4921765 14, 151.2568375 -33.4922183 14),(151.2568375 -33.4922183 14, 151.2569403 -33.4921765 14))')));
SELECT ST_AsText(ST_LineMerge(ST_GeomFromText('MULTILINESTRING Z ((151.2568375 -33.4922183 14, 151.2569403 -33.4921765 14), (151.2569403 -33.4921765 14, 151.2568375 -33.4922183 14))')));

which both return,

LINESTRING Z (151.2568375 -33.4922183 14,151.2569403 -33.4921765 14,151.2568375 -33.4922183 14)
3

So it seems that the ST_MakeLine function is the answer,

ST_MakeLine(
    LINESTRING(Point A, Point B),
    LINESTRING(Point B, Point A)
)

Your Answer

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

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