How to remove self intersections in polylines using ArcObjects?
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?
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.
(using FORTRAN 77 with ArcInfo 4.03 object code, in 1988 [The more things change...]).
the length of the line). O(N) beats O(N^2) every time.
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!