How do I determine if a varying hypothetical set of lines (example in image) needs to be sorted by X (longitude) rather than Y (latitude) programmatically to ensure they are ordered from 1 to 14 as described by the arrow?
The example set of lines is only an example and can occur in an number of different orientations and permutations.
I will always know which line needs to be 1 for each set of lines, but the rest of the lines need to be ordered in proper sequence.
UPDATE_05_18_2017: To clarify this post a bit if anyone comes across it in the future.
- Lines can come into the program in any arrangement;
- Due to digitizing when creating these lines the (OBJECTID, OID, FID whatever) will also get scrambled;
- A method was needed to order these lines;
- The Sort tool, an SQL "ORDER BY" statement with a da.UpdateCursor, etc. would sort the records, but since the lines can come in any orientation, to my knowledge there is no way to achieve an accurate sort.
My work-around was to educate the editors so that while editing they maintained some logical OID order. With an ordered OID field I could then query and loop though the data reliably as desired.
I thought to calculate average bearings, and sort on their basis since lines will follow a defined orientation, but the lines shown in the example are 118.9degrees which would lend them to be sorted by Y:
if 45 <= avgGbearing <=135 or 225 <= avgGbearing <= 315:
using the .firstPoint(shown), .midPoint or .lastPoint coordinate would not sort the lines 1 to 14 appropriately:
The data is stored in a Microsoft (JET) Access personal geodatabase. I am using ArcGIS Desktop version 10.1 ArcInfo License.