How to spatially sort lines

3570
4
Jump to solution
01-08-2014 10:29 AM
YichiLiu1
New Contributor III
Hi all,

I have a line shapefile and I split the line into multiple line segments using Split Line At Vertices. The problem I have is that after split the line, the first feature (FID = 0) is at the middle of the whole line, highlighted as following.
[ATTACH=CONFIG]30355[/ATTACH]

How can I spatially sort the line features so that the starting feature is the very first feature in attribute table, and the ending feature is the last feature in the attribute table, and the rest follows the direction of the line?

I have tried the SORT tool, it didn't seem to work for me. The order changed, but the first feature still did not start at the starting point of the line.

Thank you very much!
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor
Hi all,

I have a line shapefile and I split the line into multiple line segments using Split Line At Vertices. The problem I have is that after split the line, the first feature (FID = 0) is at the middle of the whole line, highlighted as following.
[ATTACH=CONFIG]30355[/ATTACH]

How can I spatially sort the line features so that the starting feature is the very first feature in attribute table, and the ending feature is the last feature in the attribute table, and the rest follows the direction of the line?

I have tried the SORT tool, it didn't seem to work for me. The order changed, but the first feature still did not start at the starting point of the line.

Thank you very much!


For the SORT tool, did you try the spatial sort options?  They should work in combination with the attribute to group and arrange the lines.

If that does not work you could use Create Routes on the original lines (preferably) or these split lines to create a set of Linear Referenced Routes based on these lines.  Set the orientation corner priority to build from whatever end you consider to be the origin direction.  Then use the Located Features on Route tool with a 0 tolerance (or very small) to get an event table containing the ObjectID of the split lines and the measures of the end points of those lines.  You can then use the Sort tool to sort based on measure sequencing.  Join the sorted table to the split lines and transfer the table ObjectIDs to them (or the measures).  If you summarize for the Min ID value of each sequenced set of line segments, you can join that summary to the split segments and use it to recalculate each set's ID sequence to start at 0 or 1 using the field calculator.

If the original lines make up the complete path you are trying to sequence and you have multiple digitized orientations that cannot be resolved by a common corner orientation, add a From_M and a To_M double field to your original unsplit lines.  Calculate the From_M as 0 and the To_M as the length of the original unsplit line.  Then Create Routes from those fields and follow the rest of my instructions from the previous paragraph.  After you overlay the split lines on these Routes with the Locate Features Along Route tool every split segment event will be oriented and sequenced according to the original digitized direction of each unsplit line.

If you did not really want to split at every vertex (which would split at every corner angle) and instead wanted lines all to have identical segments lengths even if they bent around a corner, there are ways to build an event table for such routes to do that directly without ever using the split line at vertices tool.  Excel can create such an event table pretty easily.

View solution in original post

0 Kudos
4 Replies
RichardFairhurst
MVP Honored Contributor
Hi all,

I have a line shapefile and I split the line into multiple line segments using Split Line At Vertices. The problem I have is that after split the line, the first feature (FID = 0) is at the middle of the whole line, highlighted as following.
[ATTACH=CONFIG]30355[/ATTACH]

How can I spatially sort the line features so that the starting feature is the very first feature in attribute table, and the ending feature is the last feature in the attribute table, and the rest follows the direction of the line?

I have tried the SORT tool, it didn't seem to work for me. The order changed, but the first feature still did not start at the starting point of the line.

Thank you very much!


For the SORT tool, did you try the spatial sort options?  They should work in combination with the attribute to group and arrange the lines.

If that does not work you could use Create Routes on the original lines (preferably) or these split lines to create a set of Linear Referenced Routes based on these lines.  Set the orientation corner priority to build from whatever end you consider to be the origin direction.  Then use the Located Features on Route tool with a 0 tolerance (or very small) to get an event table containing the ObjectID of the split lines and the measures of the end points of those lines.  You can then use the Sort tool to sort based on measure sequencing.  Join the sorted table to the split lines and transfer the table ObjectIDs to them (or the measures).  If you summarize for the Min ID value of each sequenced set of line segments, you can join that summary to the split segments and use it to recalculate each set's ID sequence to start at 0 or 1 using the field calculator.

If the original lines make up the complete path you are trying to sequence and you have multiple digitized orientations that cannot be resolved by a common corner orientation, add a From_M and a To_M double field to your original unsplit lines.  Calculate the From_M as 0 and the To_M as the length of the original unsplit line.  Then Create Routes from those fields and follow the rest of my instructions from the previous paragraph.  After you overlay the split lines on these Routes with the Locate Features Along Route tool every split segment event will be oriented and sequenced according to the original digitized direction of each unsplit line.

If you did not really want to split at every vertex (which would split at every corner angle) and instead wanted lines all to have identical segments lengths even if they bent around a corner, there are ways to build an event table for such routes to do that directly without ever using the split line at vertices tool.  Excel can create such an event table pretty easily.
0 Kudos
RichardFairhurst
MVP Honored Contributor
In any case, for me all matters involving sequencing line segment events along a path will be normally be pinned to an LR Route at some point.  So even if you have to combine the original lines I would probably do a spatial join to determine all touching pairs of original lines for example and create routes based on those lines from a standard corner orientation.

The other alternative is to use Network Analyst for sequencing paths across a line network.  It can cover longer paths that include lines that do not have to share any common ID attributes, only spatial connectivity that can be traversed from a start point to an end point.
0 Kudos
RichardFairhurst
MVP Honored Contributor
Final thought for a simpler approach.  Just create routes using the Create Routes tool to form the full paths you want with separate Route IDs.  Then use the Split Line at Vertices tool directly on the Routes.  Create a From_M and To_M double field on the split up segments and use these two Python Calculations to populate them respectively:

!Shape.FirstPoint.M!
!Shape.LastPoint.M!

You can then use the Sort tool to sort on the Route ID and either the From_M or To_M field values to order the segmented lines to follow the original Route path (or follow the reverse path along the route if you use a descending sort for the measure field).

This approach would require that each Route path was a simple path that had no branches (three or more segments ends that meet together), self crossings, or closed loops so that it produced a set of ever increasing measures at each vertex along the Route.  There are ways to identify which Routes meet this criteria and which do not.  Any complex paths would require some level of manual intervention after segmenting the lines to force the Route measures at branches and loop locations to resolve into simple sequential paths.
0 Kudos
YichiLiu1
New Contributor III
Thank you Richard for your great ideas. I ended up with writing my own script to fit in my project. But your suggestions definitely helped.
0 Kudos