I have a PostGIS table with some overlapping polygon and need a PostGIS view where no polygon is overlapping and the data is aggregated (like in the picture).
With a Union of ST_Intersection() and ST_Difference() I get the upper 3 polygons, but then I'm missing the Polygons with no overlap?
SELECT ST_Intersection(a.geometry, b.geometry), a.color||','||b.color as color
FROM mytable a, mytable b
WHERE a.fid < b.fid AND ST_INTERSECTS(a.geometry, b.geometry)
UNION
SELECT ST_Difference(a.geometry, b.geometry), a.color as color
FROM mytable a, mytable b
WHERE a.fid < b.fid AND ST_INTERSECTS(a.geometry, b.geometry)
How do I include the polygons with no overlap? Is there maybe an easier solution for my problem, like a split/aggregate function?