Search code examples
pythonpostgresqlgispolygonpostgis

Modify polygons so that they don't overlap and area stays the same


I have a set of polygons and they can overlap with each other, like this: enter image description here

I want to modify them in such a way that they don't overlap and the resulting surface area stays the same. Something like this:

enter image description here

It is okay if the shape or the position changes. The main thing is that they should not overlap with each other and the area should not change much (I know the area changed a little in the second image but I drew it manually thus let's just assume that the areas did not change).

I am trying to do it programmatically with the help of Python. Basically I stored polygons in a PostGIS database and with the help of a script I want to retrieve them and modify them.

I am very new to GIS and thus this seems like a difficult task.

What is the correct way of doing it? Is there an algorithm that solves this kind of problems?


Solution

  • Here is what I did:

    Iterated over all the polygons and found overlapping polygons. Then, I moved the polygon in different directions and found the best moving direction by calculating the minimum resulting overlapping area. Then I simply moved the polygon in that best direction until there is no overlapping area.