I am writing a post-processing flow on Python. I am trying to come up with an algorithm to remove the small holes from the polygon.
I am using osgeo OGR right now, but I'm ok to do this part with shapely instead.
Currently, my solution is using Buffer like: geometry.Buffer(0.2 * 1 / 111111)
This works most of the time, but sometimes GDAL eats the whole memory on the machine and just crashes. I guess this is not optional at all. How can I accomplish my desired result?
The long gap on the right must persist, only the holes that are smaller the certain threshold have to be removed.
Best Answer
You can use the following example script. The script removes all holes from a polygon whose area is smaller than
eps
.Before:
After:
For a multipolygon, you should iterate over the list of its polygons as well.
Before:
After: