Null Doesn’t Mean Zero?

940
0
08-02-2011 02:25 PM
Labels (3)
by Anonymous User
Not applicable
0 0 940

How to add different-sized rasters with NoData Values 


One of the most common forum topics is on how to add two rasters with different spatial extents and get a result more than just where the two rasters overlap. Well, the reason the result is only those areas has to do with null values.

There are environment variables to modify to ensure that the rasters line up (snap raster) and the extent is preserved during the process (Spatial Extent). Fixing the environment setting alone will still not fix the output of the process. If you modify the spatial extent to match the "union of inputs", the output raster will have the correct spatial extent, but the only values will be the values where the two rasters overlapped. So what is going wrong?

Obviously it is the pixel values ... or, wait, I guess it isn't that obvious. Try this piece of wisdom provided by forum poster and Product Engineer, Eric R.

Pixel value + NoData Pixel = NoData Pixel
Pixel value + 0 = Pixel value
Pixel value + Nothing (because your extents are different) = Nothing.

Two different rasters used in calculation (NoData is red).

Sum of Rasters



You may be asking, "What is actually happening? Are the values being used in the analysis or not?" Well, the answer is they will be as long as part of that equation doesn't include a null value. If there is a null value present that will make the output null, then the output will not be correct. 

The next question is how to fix it. Bear in mind, both solutions require you to make the rasters that are being used as the inputs match in spatial extent, pixel registration and cell size. You can use the Copy Raster tool and set the appropriate environment settings to accomplish this. Once you have corrected the rasters, then there are two options depending on the desired output,1. Set the NoData values to a value of zero, so that when they're added together, the output will have the correct spatial extent and values from both rasters.

Output from Setting the NoData value (blue pixels = 0)

2. Utilize the Con( IsNull ) workflow to include all of the pixels and add them where appropriate.

Con(IsNull("RasterSMALL"),"RasterBIG, ("RasterSMALL" + "RasterBIG"))

Output from Con Tool



To recap, there are options to handle the NoData cells. Depending on what output you're trying achieve, there are different techniques. It's also important to understand the effect that NoData has when used in raster calculation. 

There is a related forum post that discusses using Python to sum multiple rasters together: Calculate sum of 2334 raster layers.Jeff S. - Geodata Raster Support Analyst