4

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

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

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.

library(raster)
DEM <- raster("/Users/.../input.tif")
dem_low <- aggregate(DEM, fact = 4, fun = mean)
writeRaster(dem_low,'/Users/output.tif',options=c('TFW=YES'))
rm(DEM,dem_low)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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