TransWikia.com

Downsampling Geotiff using summation - Gdal/Numpy

Geographic Information Systems Asked by DavBar on January 14, 2021

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.

2 Answers

GDAL 1.10 added a few resampling methods which will help, see gdalwarp. In particular, the -r average method, documented as:

average resampling, computes the average of all non-NODATA contributing pixels.

This isn't tested, but should look something like:

gdalwarp -t_srs EPSG:4326 -tr 0.5 0.66 -r average fine_one_sq_km.tif coarse_average.tif

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).

Otherwise, scipy.ndimage.measurements.sum can be used to aggregate multidimensional sums. But this may rely on perfect matchings between grids.

Correct answer by Mike T on January 14, 2021

Apparently, gdalwarp got a new sum method in GDAL release 3.1.0, see release notes. Adapting from the above solution:

gdalwarp -t_srs EPSG:4326 -tr 0.5 0.66 -r sum fine_one_sq_km.tif coarse_sum.tif

Answered by jhat on January 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP