By Marcel Campion


2019-01-12 16:24:00 8 Comments

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 comments

@cokrzys 2019-01-16 18:38:29

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

https://www.gdal.org/gdal_translate.html

@Marcel Campion 2019-01-14 15:07:04

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)

Related Questions

Sponsored Content

0 Answered Questions

Selecting raster pixels based on dem range

0 Answered Questions

How to compute Tree Cover Loss by year in QGIS?

1 Answered Questions

[SOLVED] Unexpected behaviour of extract function in the raster package

2 Answered Questions

[SOLVED] How to calculate raster statistics for each values in a band?

  • 2017-05-29 12:38:59
  • Putraditama
  • 2899 View
  • 4 Score
  • 2 Answer
  • Tags:   qgis rasterstats

1 Answered Questions

2 Answered Questions

[SOLVED] Point file to raster

0 Answered Questions

1 Answered Questions

Sponsored Content