I have defined a view in postgres that returns a set of polygons and can be queried as follows:-
SELECT wkb_geometry, grade_count FROM ng_schema.grade_count_report [sql.where] order by grade_count asc
This returns me a set of polygons with varying values of grade_count
What I want to do next is find geometries that overlap and cut out the overlap from the geometry that has the lower grade_count. Where they were equal I would cut the geometry with the largest area.
How best to do this?
UDATE: To be clear when I say "has the lower grade_count" this is the lower grade count of the two intersecting geometries NOT the lower grade_count of all of them as the answer below has calculated.
So I need to find ALL intersections across ALL geometries and clip them all with the LOWEST grade_count of the two losing part of its geometry.