Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions rio_tiler/io/rasterio.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from rio_tiler.utils import (
CRS_to_uri,
_validate_shape_input,
create_cutline,
has_alpha_band,
has_mask_band,
)
Expand Down Expand Up @@ -254,6 +255,7 @@ def tile(
tile_y: int,
tile_z: int,
tilesize: int = 256,
aoi: Optional[Dict] = None,
indexes: Optional[Indexes] = None,
expression: Optional[str] = None,
buffer: Optional[float] = None,
Expand All @@ -280,6 +282,11 @@ def tile(
f"Tile(x={tile_x}, y={tile_y}, z={tile_z}) is outside bounds"
)

vrt_options = kwargs.pop("vrt_options", {})
if aoi is not None:
cutline = create_cutline(self.dataset, aoi, geometry_crs="epsg:4326")
vrt_options.update({"cutline": cutline})

return self.part(
tuple(self.tms.xy_bounds(Tile(x=tile_x, y=tile_y, z=tile_z))),
dst_crs=self.tms.rasterio_crs,
Expand All @@ -290,6 +297,7 @@ def tile(
indexes=indexes,
expression=expression,
buffer=buffer,
vrt_options=vrt_options,
**kwargs,
)

Expand Down
8 changes: 7 additions & 1 deletion rio_tiler/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ def read(
"dtype": src_dst.dtypes[0],
}

if nodata is not None:
if nodata is None:
vrt_params.update(
{
"init_dest_nodata": False
}
)
else:
Comment on lines +156 to +162
Copy link
Author

@DanSchoppe DanSchoppe Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new change that adds VRT option "init_dest_nodata": False for datasets in which no nodata is specified.

Important context:
We're building against the most recent master GDAL content, not the GDAL version that rasterio usually comes with. As of the time of this writing, that's GDAL commit 92e2427.
/Important context

This change is necessary to accommodate COGs that contain an internal per-dataset mask. Without this change, when I would request a raster tile via TiTiler, GDAL was throwing an error:

Traceback (most recent call last):
  File "rasterio/_io.pyx", line 969, in rasterio._io.DatasetReaderBase._read
  File "rasterio/_io.pyx", line 199, in rasterio._io.io_multi_band
  File "rasterio/_io.pyx", line 205, in rasterio._io.io_multi_band
  File "rasterio/_err.pyx", line 325, in rasterio._err.StackChecker.exc_wrap_int
rasterio._err.CPLE_AppDefinedError: IReadBlock failed at X offset 0, Y offset 0: INIT_DEST was set to NO_DATA, but a NoData value was not defined. This warning will become a failure in a future GDAL release.

(NOTE: this was an actual thrown exception from rasterio/GDAL that resulted in failed tile requests, not a warning. I can't explain why the error message seems to incorrectly assert that it's a warning.)

It was surprising to me that INIT_DEST: NO_DATA would be set at all. I want TiTiler + rio-tiler to simply respect the mask configuration of the target dataset rather than bake in some assumption about the target dataset. I think this INIT_DEST: NO_DATA is a result of rio-tiler-supplied VRT param "add_alpha": True, which GDAL is calling out as problematic when the source dataset doesn't have a NODATA value defined.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @vincentsarago. Curious if this makes sense to you, and if it's perhaps a desirable upstream change to rio-tiler for future versions of GDAL — as mentioned in the above comment, this is perhaps an issue thanks to the bleeding-edge build of GDAL I am running against.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fully sure to understand the change
in rio-tiler, we do pass nodata and src_nodata to construct the VRT document and init_dest_nodata=True by default so I'm not quite sure why would GDAL raise an error

maybe something changed in GDAL and rasterio is not yet up to date for it 🤷

vrt_params.update(
{
"nodata": nodata,
Expand Down