[gdal-dev] Prevent extrapolating with ReadAsArray when resampling

Rutger kassies at gmail.com
Thu Jan 4 08:18:59 PST 2018


Dear list,

I regularly use (and enjoy!) the resampling option when using the
ReadAsArray method of a Dataset. However, i noticed that in the case of
nodata values in the raster, the method extrapolates "into" those nodata
values. This is not always desirable in my case, especially when using any
resampling algorithms other than Bilinear or Nearest, since these can
overshoot significantly.

This made me wondering if there is a way to prevent this extrapolation? One
thing i noticed it that when the nodata value is non-numerical, like NaN,
there is a lot less extrapolation (eg more nodata values returned). That
could be used a workaround, but it not convenient to map numerical nodata to
NaN values before reading the input. 

In the process of exploring the behavior, i also encountered some issues
(perhaps a bug?) when using Lanczos in combination with certain datasets and
certain output grids. This happened especially when the output size is an
uneven factor of the input size, like (buf_xsize=xsize*3, buf_ysize=ysize*3)
or (buf_xsize=xs*5, buf_ysize=ys*5) etc.

Here is a notebook showing what i did with a linearly increasing grid:
https://gist.github.com/RutgerK/30fbd03d9b2ab79861eedfbb95064732

And a random grid:
https://gist.github.com/RutgerK/bdbd6c124224cf49961082e1620ce604

Regards,
Rutger





--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html


More information about the gdal-dev mailing list