# Creating a new raster showing values based on how many rasters overlap

Intro to GIS student here.

Hopefully I can articulate this issue clearly:

Currently, I have six raster layers that I am trying to create a new layer out of. I think the best way to describe the new layer is using a venn-diagram analogy.

Imagine the classic 3 circled venn diagram. Each of these circles is a unique raster.

I am trying to create a new raster that assigns values based on how much overlap there is. So, for example, areas of the venn diagram where none of the circles over-lap would have a value of 1, areas where there is overlap between two circles would have a value of 2, and the area where all three circles overlap would have a value of three.

So with my actual project, the new layer would look something like:

Areas with 6 overlap = 6
Areas with 5 overlap = 5
Areas with 4 overlap = 4
and so on.

I've googled but haven't worded my problem yet, or there is no easily found tutorial for this.

• How about summing across a presence/absence Boolean for each image (a Con where Null = 0, NotNull = 1)? Mar 25 at 5:18

The basic idea for this solution is using Raster Calculator. A bit tricky is how to deal with varying extents (solution: Virtual Raster) and NoData values resulting from this (solution: Fill NoData values). So proceed as follows:

1. Create a Virtual Raster from all input rasters (see second last screenshot below) to get the maximal extent of the combined rasters.

2. Run `Raster Calculator` for `raster1`, using the extent of the virtual layer created in step 1 (zoom to virtual raster layer and have it selected before opening the raster calculator). Then use this expression - it simply tests if the cell contains any value:

`ABS ("raster1@1")>=0`

Save the resulting layer, do not use on-the-fly raster as this seems not to be able to handle NoData values properly.

3. Run `Fill NoData cells` on the output of step 2 and use `0` as `Fill value`.

4. Repeat steps 2 and 3 for all your input rasters (consider using batch mode for tools used in step 2 and 3).

For each initial raster, you get a binary raster (values 0/1) for the whole extent (= extent of virtual raster, step 1), depending on the initial raster at this place has a cell value or not: see first screenshot below.

5. Run raster calculator to add a all the outputs of steps 3/4, like:

``````"Output1@1" + "Output2@1" + "Output3@1"
``````

If you want, you can use Polygonize to create a vector layer from these shapes.

Screenshot: binary rasters (output steps 3/4) in semi-transparency. White: extent of initial raster, black: outside extent of initial raster: *Output of step 5: raster values indicate how many of the initial rasters overlap at each pixel. Blue is the extent of the initial rasters, green is where two rasters overlap, yellow is where all 3 rasters overlap. Violet is where there is no of the initial rasters it all: * And this is how the initial rasters looked like - different color ramps to be able to discern the difference: Polygonized: the shapes in vector format. The labels and the graduated color ramp show the number of rasters each polygon overlaps: • This worked. Thank you so much! One strange thing though: Step 3 gave me different results depending on if I made a temporary or permanent raster. When left temporary, I got the desired results - a raster with a 1 and 0 value. When I saved it permanently, however, the result was a raster with a single value of 0. Any idea why this might have happened? Or just a weird quirk of QGIS? Mar 29 at 22:05
• You're welcome. Remember to accept the answer if it solved your problem. Difficult to say what's going on with step 3 without seing your original raster data, the very settings you made and the result (output) of step 2. Probable in step 2, a certain value was assigned for nodata which in step 3 was not recognized as nodata. Mar 29 at 22:25