cogeotiff/rio-tiler

Reader `resampling_method` has no effect when doing Reprojection

Closed this issue · 2 comments

Discussed in #646

Originally posted by DanSchoppe October 16, 2023
On the latest release of rio-tiler (as well as several earlier 6.x releases I've tried), the resampling_method argument to Reader.tile() seems to have no effect. I haven't tested whether it affects Reader methods beyond tile().

Here's a simple recreation:

from rio_tiler.io import Reader

with Reader('https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/15/T/VK/2023/10/S2B_15TVK_20231008_0_L2A/TCI.tif') as cog:
    img = cog.tile(
        tile_x=31588,
        tile_y=47192,
        tile_z=17,
        resampling_method="cubic",
    )

with open('tile.png', 'wb') as f:
    f.write(img.render())

The resulting tile looks like:
image
... regardless of the value provided in resampling_method.

Earlier versions of rio-tiler would have produced something like:
image

From the discussion:

Ooo I think I know what's going on 😬

when we are doing reprojection (using WarpedVRT) we are creating a VRT which is aligned with the bounds (This is to make sure we fetch the overviews)

vrt_transform, vrt_width, vrt_height = get_vrt_transform(
src_dst,
bounds,
height=height,
width=width,
dst_crs=dst_crs,
)

Because the VRT will be of the same size as the desired output, there will be no downscaling/upscaling happening there

resampling=io_resampling,

which is why the resampling_method will have no effect 😭