TransWikia.com

Bilinear resampling with GDAL leaves holes

Geographic Information Systems Asked on March 18, 2021

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:
Original image

The resampled raster image (1-degree equirectangular projection) looks like this:
Resampled image

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?

One Answer

When re-gridding to a coarser raster, always use an aggregation method, such as 'average' for continuous variables or 'mode' for categorical variables. Other appropriate aggregate methods for continuous variables include min, Q1, median, Q3 and max.

Interpolation algorithms including 'bilinear' (among others) should only be used when re-gridding to a finer resolution. Expect weird/bad results when re-gridding to a coarser raster, since that's not what these algorithms are designed for.

Answered by Mike T on March 18, 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