I'm attempting to down-sample a raster (resampling to a coarser/ larger pixel size) with continuous, floating-point values. I generally use bilinear resampling for the up-sampling case (resampling to a finer resolution), so I thought I would use it here, too. I'm finding that whether I use gdal.ReprojectImage()
or gdal.Warp
(which is a wrapper for gdalwarp
), I get large NoData chunks in the output image wherever there was at least one NoData value in the input image. I would have assumed that as long as there was some data in an output pixel (which subsumes multiple smaller pixels), there would be a valid output value.
The effect is quite striking visually. The original raster image (9-km resolution on an equal-area grid) looks like this:
The resampled raster image (1-degree equirectangular projection) looks like this:
Sample Python code used to resample the original equal-area raster is below; there is an equivalent with gdal.ReprojectImage()
but it is much more verbose.
import gdal
from gdal import gdalconst
ds = gdal.Warp(
'temp.file', original_raster,
format = 'MEM', xRes = 1, yRes = 1,
dstSRS = "EPSG:4326",
outputBounds = (-179.5, -90.5, 180.5, 89.5),
resampleAlg = gdalconst.GRA_Bilinear,
outputType = gdalconst.GDT_Float32)
In contrast, a nearest-neighbor resampling (changing resampleAlg
argument) produces a continuous 1-degree grid, with no "holes" in the output raster. Nearest neighbor is much simpler, of course, but is there an option to calculate weights for bilinear resampling in a way that NoData pixels don't contaminate output pixels in this way?
gdalinfo --version
)? Test data would still be appreciated.gdaladdo -r gauss -ro soc_mean.tif
do not seem to have holes.