[GIS] How to convert self intersecting polygon to multipolygon

algorithmgdalpolygon

Working with the union and polygonize methods in GDAL/OGR, I often end up with self intersecting polygons. The case is one polygon which essentially consists of two polygons:

Self intersecting polygon example

In the above example, the polygon has two vertices at the intersection point, but whether the lines meet and goes seperate ways at the point or crosses each other, is unknown.

  1. Are there methods for splitting a self intersecting polygon like above, into two polygons or a multipolygon?

  2. Alternatively are there any existing algorithms I could implement my self (I would rather not invent another wheel)?

Best Answer

It's strange to get such self intersecting polygons because it violates the polygon definition in OGC Simple feature access specification and may not be viewed as legal polygons.

I don't use GDAL that often, but am quite familiar with GEOS and if I remember clearly GDAL union/polygonize are built based on GEOS library. In GEOS, if you union two polygons that share one vertex coordinates, like the case in your given picture, it will return you a multipolygon. In case you might want to look into the code, here is how GEOS do it:

http://svn.osgeo.org/geos/branches/3.3/src/geom/

The relevant functions may be the Geometry::Union in file Geometry.cpp

And also the GeometryFactory::buildGeometry in file GeometryFactory.cpp

Related Question