Polygon Validity – Detecting Invalid Polygons (Self-Intersecting or Touching)

algorithmcintersectionmathematicspolygon

An invalid polygon can be defined as one that intersects itself, or one where the lines make contact, ie, the two shapes at the top of this picture.

http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Straight_skeleton_2/invalid_polygons.png

Given the XYPoints of a polygon, what logic (using C# preferably, but as long as I see logic, I can translate) could be implemented to detect these situations?

I've looked at the Bentley-Ottmann_algorithm, however this detects if lines intersect and not if they touch. Not to mention, it says in the wikipedia article that it's slow.

Best Answer

If you don't want to write something from scratch, you could possibly call Check Geometry from ArcToolbox. I've used it a few times for certain geometries. Not sure if all of the above cases will be returned as bad geometry. You may want to test the tool on a test dataset. Please keep us posted.