# Resample binary raster to give *proportion* within new cell window

I would like to go from a binary raster of forest/non-forest at 30m resolution to a raster at 240m resolution with the value of each cell being the proportion of that cell forested - i.e. the data values for the 240m cells would go from 0 (where all cells in the 30m raster were zero/non-forest) through 0.5 (where half the 30m cells were forest, half were non-forest) to 1 (where all cells in the 30m raster were forested).

Although it is has been suggested not to use bilinear interpolation on discrete data, as far as I can tell the result with binary 0/1 data would be to give an average value (i.e. a proportion between 1 and 0). Is this a sensible way to do it, or is there a better method?

I can use Arc, QGIS and Idrisi.

Use Block statistics.

This works like Focal statistics by computing a statistical summary (such as the mean you desired) within a specified neighborhood of cells (such as an 8 by 8 square, where 8 = 240 m / 30 m), except it performs this only for a regular subdivision of the grid, rather than with a set of overlapping neighborhoods, one at each cell.

You can also make use of Focal statistics if you really want to: after computing the focal mean over 8 by 8 squares, resample to a 240 m grid using nearest neighbor resampling. When the grids are registered to one another (i.e., they have the same origin) this should give the same result as `block statistics`. (I won't guarantee that: some arbitrary choices have to be made when new cell centers coincide with old cell corners--as they will here--and, if different committees coded the two procedures, they may have made different choices: little in ArcGIS is truly consistent, I'm afraid.)

Another approach is to create a grid of zones, one zone per square where an average is desired, and perform a zonal summary as a grid. The zones can be computed mathematically from grids of row and column coordinates (by means of the `floor` or `int` function, by reclassification, or by joining a suitable table to the attribute table).

I will close by remarking that bilinear interpolation, although it will indeed yield values in the range 0..1, is not what you want: it works by finding at most four original (30 m) grid cells surrounding the center of a new (240 m) cell and interpolating only their values. As such, it will overlook the other 8*8 - 4 = 60 original cells falling within each new block. I illustrate bilinear interpolation at http://www.quantdec.com/SYSEN597/GTKAV/section9/map_algebra.htm: the discussion begins near the middle of the page.

• Thanks whuber, this is what I did - used Block Statistics in Arc to produce the sum of the 8x8 group, then used the Raster Calculator in QGIS to divide by 64 and align the origin, extent and cell size with the rest of my data. – stuckGIS Jun 20 '12 at 18:24
• stuckGIS, you could skip the second step by using Block Statistics to compute the mean of each 8 x 8 block. Aligning the new grid is a matter of specifying the raster analysis environment appropriately, which--if done before starting the calculations--will occur automatically. That reduces your workflow to a single step: perform the block mean. – whuber Jun 20 '12 at 18:55

In ArcGIS whne you resample data using bilinear resampling it only looks at the values of the centre four cells (resample documentation). As such using this method you'll still lose data if you don't compensate for the data loss.

Given that we know that for the resampled cells you're after a proportion of the cells that are forested, we can think of it as the sum of the 30m cells divided by 64 (there are 64 30m cells in the 240m block).

This means that if we can create a new raster with the centre values as the sum of the surrounding values at 30m resolution, lowering the resolution using resample with nearest neighbour or bilinear interpolation will give us 240m cells which are the sum of the 30m cells they cover. We can do this with the focal sum tool over the 30m raster.

Lastly once we have a 240m focal sum raster, divide by 64 to get your proportion answer.

In Idrisi I'm not sure of the image sampling algorithms, likewise in QGIS, but I imagine there's something similar. Certainly in QGIS you can process the raster in Python using scipy ndimage or similar.