3

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.

Self intersection inside geometry Self intersection at edge

1
  • "I have tried to use shapely to clean the self intersections but the result is very poor." How did you use it?
    – sgillies
    Commented Jan 5, 2018 at 2:00

1 Answer 1

1

Yes, this is because pixels always share corners with 8 others. There's no silver bullet for turning the invalid polygons into valid polygons or multipolygons. That said, in your examples above it looks like the self intersections would be solved by eroding (negative buffer, in other words) the invalid polygons by a small fraction, turning them into multipolygons.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.