Ordering a set of lines so that they follow one from the other
Posted
by
george
on Stack Overflow
See other posts from Stack Overflow
or by george
Published on 2011-02-11T07:22:49Z
Indexed on
2011/02/11
7:25 UTC
Read the original article
Hit count: 101
python
Line# Lat. Lon.
1a 1573313.042320 6180142.720910 .. .. 1z 1569171.442602 6184932.867930
3a 1569171.764930 6184934.045650 .. .. 3z 1570412.815667 6190358.086690
5a 1570605.667770 6190253.392920 .. .. 5z 1570373.562963 6190464.146120
4a 1573503.842910 6189595.286870 .. .. 4z 1570690.065390 6190218.190575
Each pair of lines above (a..z) represents the first and last coordinate pair of a number of points which together define a line. The lines are not listed in sequence because I don't know what the correct sequence is just by looking at the coordinates (unless I look at the lines in a map).
Hence my question: how can I find programmatically (in Python) what the correct sequence is, so I can join the lines into one long line, keeping in mind the following problem: - a 'z' point (the last point in a line) may well be the first point if the line is described as proceeding in the opposite direction to other lines. e.g. one line may go from left to right, another from right to left (or top to bottom and viceversa).
Thank you in advance...
© Stack Overflow or respective owner