I have a PostGIS table testtin2 which is a sort of pseudo TIN consisting of a single multilinestring geometry, which I am intersecting with another table align, also a multilinestring, to generate a set of coordinates along an alignment (or alignments) via the following query...
SELECT ST_X(q1.int_pnt), ST_Y(q1.int_pnt), ST_Z(q1.int_pnt)
FROM
(SELECT ST_Intersection(align.geom, testtin2.geom) as int_pnt
FROM align INNER JOIN testtin2 ON ST_Intersects(align.geom, testtin2.geom)
WHERE ST_isvalid(align.geom)='t' AND ST_isvalid(testtin2.geom)='t') As q1;
Which works fine except for the fact that the resulting output is seemingly in a 'random' order. Is there a way this query might be modified or re-written such that the coordinates come out in the correct linear sequence along the alignment linestring(s) from the align table?
I need this to happen so that the drafting software I am passing the coordinates to will join the dots up in the correct order.
Thanks in advance.