3

I want to merge linestring in the correct order in postGIS, but sometime they are reversed so something like this :

select astext(linemerge(ST_union(
ST_GeomFromText('LINESTRING(3 3, 2 2)'),
ST_GeomFromText('LINESTRING(1 1, 2 2)'))));

returns this :

"LINESTRING(1 1,2 2,3 3)"

But I want this :

"LINESTRING(3 3, 2 2, 1 1)"

I really don't know what to do.

2 Answers 2

5

If you just want to reverse a geometry you can just use ST_Reverse (returns the geometry with vertex order reversed).

If the problem is you want to keep some arbitrary order, I don't think you can do it using ST_Union (the definition for ST_Union being point set union, as in ordering is not guaranteed).

0

Give it to diciu. I just want to add an example:

select ST_AsText(ST_Reverse(ST_GeomFromText('LINESTRING(3 3, 2 2)')));

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.