I am trying to do a union across thousands of different geometries. The geometries can be very complex so a naive union can take many hours. I then want to dump these geometries so each polygon becomes its own shape rather than one very large multipolygon.
However, I have extra information about the geometries. The total area covered by the geometries is split up into squares. Each geometry is contained within a square and thus can only touch the geometries of the 8 adjacent squares. Is there some way to use this extra information about which polygons could possible intersect in order to reduce the time of the union?
I can do this either in PostGIS or in Python.