[gdal-dev] problem with interpolation on GDAL RasterIO ?

Andrea Battisti battisti at actgate.com
Thu Oct 17 07:18:32 PDT 2019



Il 09/10/19 15:10, Andrea Battisti ha scritto:
> Hi all,
> 
> 
> I think I found a glitch in how bilinear interpolation is applied when 
> reading a sub block of a dataset.


Hi,

I was able to nail down the issue described in my previous message.

Looks like it is happening here:
https://github.com/OSGeo/gdal/blob/master/gdal/gcore/rasterio.cpp#L1228

If my understanding is correct, when the data type of the output buffer 
and the type of the input differ (eg Float64 vs Float32), that 
GDALCopyWords call writes to the wrong buffer (pData, instead of 
pTempBuffer).
That gets overwritten by random stuff when the pData buffer is then 
filled from the temporary MEM dataset at line 1289.

The problem is not visible if the type of input/output buffer are the 
same, as in that case pData is used anyway as output.


Given that, I tried to re-purpose that GDALCopyWords call as:

	GDALCopyWords(
		&fNoDataValue, GDT_Float32, 0,
		static_cast<GByte*>(pDataMem) +
		nLSMem * (j + nDstYOff) +
                 nDstXOff * nPSMem,
                 eDTMem, static_cast<int>(nPSMem),
                 nDstXCount);

in order to make it use the right buffer even when the input/output data 
types differ.

That fixes my use case and I think it makes sense in general, but I 
would really appreciate a quick review on this as there might be other 
places to update as well.

I have created an issue here:
https://github.com/OSGeo/gdal/issues/1941

What is the best way to go forward with this?


Thanks,
-- 
Andrea Battisti
Computer Science Engineer


More information about the gdal-dev mailing list