I'm looking for the most efficient way to split a polygon (possibly with holes) with a set of lines (which can intersect) in C++ with GDAL/OGR or any other library which can prove useful.
As shown in the figure below, I would like to split the polygon with the red lines, which would result in multiple polygons (possibly with holes):
Performance is a big issue as I need to make such calculation thousands of times. For now, I'm doing the following:
- Build a MULTILINESTRING with every lines
- Buffer it (distance 0.001, precision is not a big issue)
- Compute the difference with the POLYGON
Profiling shows that
Difference() is a bottleneck.
Some solutions rely on PostGIS (e.g.
ST_Split) or other command line/query language tools with no direct binding in the C++ API of GDAL/OGR.