Input:
I have many many small simples polygons representing some "field of view" from points. Lots of them overlap one or many others.
Goal:
I would like to give "some kind of" "weight" attribute to each polygon based on "how many others do they see in their area".
Desired operations:
in the world of rasters:
It's a bit fuzzy said like that but I think the easiest operation would be to rasterize them and then sum up, for each pixel of the raster, how many "observers" do see them.
In other words, how many polygons have contributed to each pixel.
This would lead to a basic heatmap with a Z-value as "contributing polygons count" for each pixel.
(Precision: I do not use any DEM and viewshed analysis for that but the idea is the same over a plane, where the viewed area is defined by the polygons themselves).
Up to this point it is OK, but then, how to get back to the vector world of the initial polygons in order to attribute each polygon a "weight"?
I can sum the values up. Simply.
But is there any algorithm already defined therefor and how to perform this operation?
Extra:
for each rasterized polygon, it would be nice if pixels values were not just simply set to 1 (seen) or 0 (not seen) but rather to float values between ]0-1] (0 would still be used for: "not seen" and only that) with a weight applied as a function of the distance to the observer.
in the world of vectors:
An other (simpler) way to achieve this (a little differently but maybe more efficiently) is to stay in the world of vectors by simply attributing to each polygon:
1. "what is the maximum number of overlapped (stacked) polygons within the considered polygon" (it may be 10 other polygons intersecting the query polygon but with no overlap between them, thus this number would still be 1, if two of them overlap (and not the 8 other) within the query polygon area, then it would be 2, if all 10 overlaps themselves on the query polygons, it would be 10), or:
2. the cumulative number of other polygons overlaps (10 simples overlaps would give 10, even if some polygons overlap others on the query polygon) or:
3. a mix from the two previous points: the cumulative way + the stacked way, e.g. if 10 polygons overlap the query polygon and if two of them overlaps themselves within the query polygon, then it would be 10+2=12 (or 10+1=11 depending on how important stacking is)
Simple image examples to better clarify the request:
Legend: 10 simple overlaps. With method 1 the result would be 1.
With methods 2 and 3 it would be 10.
Legend: 8 simple overlaps + 1 "level 2" overlap. With method 1 the result would be 2.
With method 2 it would be 10 and with method 3 it would be 10+1=11 (or 10+2=12, as if the deeper blue area top-left on the query polygon would count as 2 instead of 1).
Is there an existing function to retrieve this number for each of the 3 methods described here above for a given query polygon (in red in examples) and store this value as an attribute for this query polygon?
Working environment:
It is Python2.7 on a Linux based system which is the candidate for this task.
Working with a postgreSQL database.
Computational efficiency should not suffer too much, is possible.