I have a GeoTIFF which is at 30m resolution. I need to downsample it to 250m resolution (using some aggregating function such as mean, mode, sum). My stack is python (rasterio and GDAL bindings)
I can find a way to do this directly using numpy writing some nasty double loops and iterating over the matrices directly but looking for a cleaner way.
Note that the main issue is that 250 is not a multiple of 30 and there will be some overflow. For instance if the aggregating function is the sum the algorithm would be to use:
- 8 X 8 block which is 240m X 240m in base resolution
- Chose a partial pixel strip at 10m X 10m to complete the sum to 250m
- The value for 2. would be area weighted and added to the sum from 1.
Please let me know if I was unclear. Again I can find a brute force way to do it using matrix manipulations but was wondering if there is an elegant way. I am open to using R
also and read about the projectRaster
and aggregate methods but they seem to work on integer cut offs also.
In general it may be really cumbersome to do this for an arbitrary resolution say 31.567m or so.