Select to view content in your preferred language

How to remove self intersections in polylines using ArcObjects?

5070
3
Jump to solution
10-03-2012 03:16 PM
DuncanHornby
MVP Notable Contributor
All,

I have a river network and a tool I am creating is failing because there are self intersections in the polylines that make up the river network (see attached image of a good example of a polyline with this problem, these can be less than a meter in length so very hard to spot visually, unless zoomed right in).

Now I've written some code that can go through the entire network and identify these "offending" polylines.  I use the ITopologicalOperator and ask if it IsSimple, a False tells me that the polyline has a self-intersection.

So I have a programmatic way of find these on mass but what I am unsure is how to fix these programmatically on mass. I need to remove these loops.  As they are so small a simple deletion of a vertex will resolve this (don't care which one) and I have been doing that manually. I want to automate this but I can't figure out how to resolve it in ArcObjects. Has anyone tried to do this and willing to share their technique?

Duncan
0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor
All,

I managed to "dream up" a solution overnight! I wrap the polyline with a pointcollection interface and systematically remove a vertex and test if it still has a self intersection. Eventually it will remove a vertex that will stop it being self intersecting. I then go back to the original polyline and remove that specific vertex, et Voila!

I don't know if this is a slick solution to the problem but it works. The only limitation I can think of is that this method expects the self intersection to be generated by only one erroneous vertex, which in my case is typically the problem.

Duncan

View solution in original post

0 Kudos
3 Replies
DuncanHornby
MVP Notable Contributor
All,

I managed to "dream up" a solution overnight! I wrap the polyline with a pointcollection interface and systematically remove a vertex and test if it still has a self intersection. Eventually it will remove a vertex that will stop it being self intersecting. I then go back to the original polyline and remove that specific vertex, et Voila!

I don't know if this is a slick solution to the problem but it works. The only limitation I can think of is that this method expects the self intersection to be generated by only one erroneous vertex, which in my case is typically the problem.

Duncan
0 Kudos
VinceAngelo
Esri Esteemed Contributor
I remember a colleague addressing this issue with the output of a stream digitizer
(using FORTRAN 77 with ArcInfo 4.03 object code, in 1988 [The more things change...]).

The "knots" could be removed by identifying the segments that changed direction
by nearly 180 degrees. You could speed up your solution (and make it handle multiple
occurances) by passing through the vertex list once, calculating the orientation of
segments from A to B ( atan2(By-Ay,Bx-Ax) ) and B to C ( tan2(Cy-By,Cx-Bx) ) and
looking for an absolute delta greater than 165-170 degrees. If you organize the loops
right, you'll only need to call atan2 nverts-1 times (sliding the A B C designations across
the length of the line). O(N) beats O(N^2) every time.

- V

PS: You should also look for coincident points (Cy-By == 0 && Cx-Bx == 0) while you're at it...
0 Kudos
DuncanHornby
MVP Notable Contributor
1988! Now you are just showing off! :)Your solution was what I was expecting but it blows my mind, definitely going away to have a good think about it.Many thanks!
0 Kudos