Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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,

Thanks.

share|improve this question

2 Answers 2

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).

share|improve this answer

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

select ST_AsText(ST_Reverse(ST_GeomFromText('LINESTRING(3 3, 2 2)')));
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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