I am trying to downsample a 1 square km raster dataset to a much larger (.5 degree x .66 degree) dataset by summing all of the pixel values within this large grid cell.
gdal_warp does not contain a summation resampling method so I'm wondering if anyone has figured this out before.
Best Answer
Depending on the version of GDAL, there are a few different resample options available; see gdalwarp.
GDAL 1.10 or later using
-r average
This isn't tested, but should look something like:
Then to get the sum, multiply the average by the number of pixels of the fine resolution raster in one pixel of the coarse resolution raster, which hopefully is constant (you could assume it is).
GDAL 3.1 or later using
-r sum
This should look like this:
Otherwise,
scipy.ndimage.measurements.sum_labels
(orsum
for older versions) can be used to aggregate multidimensional sums. But this may rely on perfect matchings between grids.