Select to view content in your preferred language

# Sorting Linear Features

1416
7
04-29-2013 07:27 AM
by
New Contributor II
I'm having a bit of trouble sorting a polyline feature class in the correct order.

Basically I have a polyline feature calss with multiple features in it that form a single line. This feature class was produced by taking a single polyline and splitting it at specified points (using the Split at Point tool). The resulting feature class has multiple polyline features in a somewhat random order. What I need to do is re-order these feature classes from a start point at one end of the line to the end of the line. I have tried the Sort tool and that works some of the time, but not all of the time as occasionally the original line winds and turns a lot and that seems to mess up the Sort tool.

Does anyone know of a simple way or tool to do this without having to get into any crazy Python scripting that manipulates the geometry? This seems like a fairly logical need, so I'm hoping there is a simple way to do it.

Thanks,
Tags (3)
1 Solution

Accepted Solutions
MVP Honored Contributor
Use the Create Route tool.  If each end touches another end the line will rebuild successfully from one end to the other.  THe only caveat is for lines that are perpendicular to the corner you specify to build from.  Then it may grab a position closest to that corner and double back.

I assume you kept your original lines?  If so build the Route from that.  That will assign measures to the lines before you split them.  Then I would locate the point on the line to get M values for the points (just as a precaution), then split at points.  Calculate the M values to each segment (Python field calculation of !Shape.FirstPoint.M! for the from measure and !Shape.LastPoint.M! for the end measure) and that value should be your sort order for a given original Line_ID.  I believe that the split of the line will cause an interpolation of measures at the split points.  However, if NAN values appear at the end points of the split, then prior to using the Create Route tool create vertices at the split point positions so that they will have vertices where measures will be assigned (probably using a Snap tool).  Back up your data if you have to use any destructive tools like Integrate.

The Centroids of the split lines you are currently working with should allow you to do a Spatial Join to the resplit lines, assuming you have attributes you have created since splitting the lines that you need to preserve or transfer.
7 Replies
Frequent Contributor III
The data can sort either alpabetically or numerically.  If you have numbers in your sort and letters it will sort alphabetically so your numbers will not sort properly.

If you want to keep them in order when you split your best practice may be to start at the digitized beginning and split it while going down the line.

I'm having a bit of trouble sorting a polyline feature class in the correct order.

Basically I have a polyline feature calss with multiple features in it that form a single line. This feature class was produced by taking a single polyline and splitting it at specified points (using the Split at Point tool). The resulting feature class has multiple polyline features in a somewhat random order. What I need to do is re-order these feature classes from a start point at one end of the line to the end of the line. I have tried the Sort tool and that works some of the time, but not all of the time as occasionally the original line winds and turns a lot and that seems to mess up the Sort tool.

Does anyone know of a simple way or tool to do this without having to get into any crazy Python scripting that manipulates the geometry? This seems like a fairly logical need, so I'm hoping there is a simple way to do it.

Thanks,
Regular Contributor II
As far as 'sorting' to get the physical continuity of the orginal line:
section 1 connects to section 2 to section 3, and so forth
One would build a route, and the sections table would provide that order.

Without buying the Network Analyst extension, and without populating a 'step' attribute by hand,
you will need to do some "manipulation of geometry".

One way might be:
selecting the start segment,
make a feature layer of that start line
calc the step attibute you added (did I mention that?) to 1

select by location on a layer of all the lines
this should select 2 lines, the start line and the next one.
remove the start line from the selection (use select by attribute to remove step attibute is not null)

make a layer of that 'next' segment (the selected one)
calculate the step attribute to 2
... and repeat the steps above.
This time select by location  will return 3 lines:
the indentical one, the previous one, and the next one (which is the one you want)
again, use select by attribute to remove step attibute is not null to get just the new segment.

make a new layer with that one and
calc its attribute to 3

rinse. repeat.

Sort of long and tedious I know...
by
New Contributor II
The data can sort either alpabetically or numerically.  If you have numbers in your sort and letters it will sort alphabetically so your numbers will not sort properly.

If you want to keep them in order when you split your best practice may be to start at the digitized beginning and split it while going down the line.

The Sort tool also sorts the lines spatially, but as I mentioned, sometimes these lines wind and turn and that seems to mess up the Sort tool, so that is not an option. I've been re-ordering them manually, but that can take a colossal amount of time to figure out which one goes where, hence why I'm loooking for a way to automate the process. This is part of a much larger workflow, and this is the last step in order to completely automate the whole process, which is ultimately the goal here.

I've resorted to Python scripting and have met with moderate success so far.
MVP Honored Contributor
Use the Create Route tool.  If each end touches another end the line will rebuild successfully from one end to the other.  THe only caveat is for lines that are perpendicular to the corner you specify to build from.  Then it may grab a position closest to that corner and double back.

I assume you kept your original lines?  If so build the Route from that.  That will assign measures to the lines before you split them.  Then I would locate the point on the line to get M values for the points (just as a precaution), then split at points.  Calculate the M values to each segment (Python field calculation of !Shape.FirstPoint.M! for the from measure and !Shape.LastPoint.M! for the end measure) and that value should be your sort order for a given original Line_ID.  I believe that the split of the line will cause an interpolation of measures at the split points.  However, if NAN values appear at the end points of the split, then prior to using the Create Route tool create vertices at the split point positions so that they will have vertices where measures will be assigned (probably using a Snap tool).  Back up your data if you have to use any destructive tools like Integrate.

The Centroids of the split lines you are currently working with should allow you to do a Spatial Join to the resplit lines, assuming you have attributes you have created since splitting the lines that you need to preserve or transfer.
by
New Contributor II
"Then I would locate the point on the line to get M values for the points "

I'm a bit confused by this part. What do you mean and how exactly do I locate the point on the line to get M values for the points?
MVP Honored Contributor
"Then I would locate the point on the line to get M values for the points "

I'm a bit confused by this part. What do you mean and how exactly do I locate the point on the line to get M values for the points?

Use the Locate Features Along Route tool to get the M values of the points once you have an LR route system or roads established.  http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//003m00000007000000.htm  Probably this step is optional, since I believe the split at points tool will interpolate the M values of the line ends automatically.
by
New Contributor II
This was a very interesting solution that I probably wouldn't have come up with on my own. I did get this into a script that sorted the line segments properly. Basically created one route for the entire line, split the line, calculated the M value (I used the !Shape.LastPoint.M! function) and then Sorted according to the M values. Voila, the resulting feature class had the lines sorted correctly.

Thank you very much, this will allow me to automate my entire workflow for this particular project and save me some time in the future!