I have a raster file representing tree cover loss made of 30m*30m pixels taking the value 0 or 1. 0 means no loss and 1 means tree cover loss. I want to cluster these pixels into bigger pixels of the size 120m*120m (i.e. 4 pixels by 4 pixels so 16 pixels in each cluster). I plan to do this for computational reasons as by doing so I reduce the number of observations by a factor of 16. My goal is to measure the share of 30m pixels with value 1 within each 120m cluster of pixels.

I am not sure how to do this.

Here is a solution I thought of:

  • On QGIS I thought of creating a fishnet of 4 by 4 pixels and then doing zonal statistics within each cell. BUT, I could not find how to create this 4 by 4 pixels grid AND I found no solution yet on how to match perfectly cell boundaries with pixel extent (in order to have exactly 16 pixels per fishnet cell, see red cells below).

enter image description here

  • 2
    There are tools to aggregate rasters in QGIS (GRASS - r.resamp.stats, SAGA - aggregate) if you like.
    – Kazuhito
    Jan 13, 2019 at 0:25

2 Answers 2


So I found a second best solution to the question asked above.

Using R one can aggregate raster pixels by a factor, in my case a factor of 4, and then export the newly created raster. This raster can subsequently be used in QGIS.

Please note that this can take a very long time. My raster is a 80000*40000 pixels so aggregation takes about one hour per raster file.

DEM <- raster("/Users/.../input.tif")
dem_low <- aggregate(DEM, fact = 4, fun = mean)

GDAL is a great tool for re-sampling rasters as well, for example using gdal_translate:

gdal_translate -tr 120 120 -r average input.tif output.tif


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.