I am creating geometry from a raster using GDAL Polygonize in Python. My issue is that doing this creates a lot of self intersection errors. This seems to occur due to the nature of the pixel grid.
I have noticed that this occurs mostly at edges, but can sometimes occur inside the geometry as well, as shown below.
This is part of an automated pipeline so I don't want to manually fix self-intersections in QGIS or the like; the solution needs to be able to be implemented in Python code.
Is there a way to either stop the self intersections being created in the first place, or a way to clean the generated geometry in Python?
I have tried to use shapely to clean the self intersections but the result is very poor.