cogeotiff / rio-tiler

User friendly Rasterio plugin to read raster datasets.
https://cogeotiff.github.io/rio-tiler/
BSD 3-Clause "New" or "Revised" License
502 stars 106 forks source link

Better handle Dateline crossing Dataset #702

Open vincentsarago opened 4 months ago

vincentsarago commented 4 months ago

Min/Max Zoom

from rio_tiler.io import Reader

with Reader("tests/fixtures/cog_dateline.tif") as src:
    print(src.minzoom, src.maxzoom)

4 4

but it should be 7 -> 11

The issue is that rasterio's calculate_default_transform doesn't seems to handle well the dateline crossing dataset.

Potential fix in https://github.com/cogeotiff/rio-tiler/blob/main/rio_tiler/io/rasterio.py#L147-L153

vrt_options = {"add_alpha": True}
if self.dataset.nodata is not None:
    vrt_options.update(
        {
            "nodata": self.dataset.nodata,
            "add_alpha": False,
            "src_nodata": self.dataset.nodata,
        }
    )

if has_alpha_band(self.dataset):
    vrt_options.update({"add_alpha": False})

with WarpedVRT(self.dataset, **vrt_options) as vrt:
    dst_affine = list(vrt.transform)
    w = vrt.width
    h = vrt.height

Dst Transform

same as ☝️ in https://github.com/cogeotiff/rio-tiler/blob/main/rio_tiler/utils.py#L354-L356