File tree Expand file tree Collapse file tree 5 files changed +34
-1
lines changed
Expand file tree Collapse file tree 5 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 11# Release Notes
22
3+
4+ ## 5.4.2 (2025-06-27)
5+
6+ * add user warning when input dataset has both Nodata and internal Alpha/Mask band
7+
38## 5.4.1 (2024-12-16)
49
510* fix reading raster compression value with ` rasterio>=1.4.3 ` (author @glostis , https://github.com/cogeotiff/rio-cogeo/pull/300 )
Original file line number Diff line number Diff line change 2121from rasterio .vrt import WarpedVRT
2222
2323from rio_cogeo import models , utils
24- from rio_cogeo .errors import IncompatibleOptions
24+ from rio_cogeo .errors import IncompatibleOptions , NodataAlphaMaskWarning
2525
2626IN_MEMORY_THRESHOLD = int (os .environ .get ("IN_MEMORY_THRESHOLD" , 10980 * 10980 ))
2727
@@ -222,6 +222,12 @@ def cog_translate( # noqa: C901
222222 alpha = utils .has_alpha_band (src_dst )
223223 mask = utils .has_mask_band (src_dst )
224224
225+ if nodata is not None and (alpha or mask ):
226+ warnings .warn (
227+ "Input dataset has both a nodata value and internal alpha/mask band. Nodata value will be prioritized." ,
228+ NodataAlphaMaskWarning ,
229+ )
230+
225231 if colormap and len (indexes ) > 1 :
226232 raise IncompatibleOptions (
227233 "Cannot add a colormap for multiple bands data."
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ class IncompatibleBlockRasterSize(UserWarning):
99 """Rio-cogeo module incompatible raster block/size warning."""
1010
1111
12+ class NodataAlphaMaskWarning (UserWarning ):
13+ """Dataset with nodata and alpha/mask warning."""
14+
15+
1216class RioCogeoError (Exception ):
1317 """Base exception class."""
1418
Original file line number Diff line number Diff line change 2121
2222FIXTURES_DIR = os .path .join (os .path .dirname (__file__ ), "fixtures" )
2323raster_path_rgba = os .path .join (FIXTURES_DIR , "image_rgba.tif" )
24+ raster_path_rgba_nodata = os .path .join (FIXTURES_DIR , "image_rgba_nodata.tif" )
2425raster_path_rgb = os .path .join (FIXTURES_DIR , "image_rgb.tif" )
2526raster_path_nan = os .path .join (FIXTURES_DIR , "image_nan.tif" )
2627raster_path_nodata = os .path .join (FIXTURES_DIR , "image_nodata.tif" )
@@ -920,3 +921,20 @@ def test_cog_values(src_path, runner):
920921 assert cog .colorinterp == source .colorinterp
921922 assert has_mask_band (cog )
922923 assert not has_alpha_band (cog )
924+
925+
926+ def test_nodata_alpha_incompatible (runner ):
927+ """test nodata/alpha warning."""
928+ with runner .isolated_filesystem ():
929+ with pytest .warns (UserWarning ):
930+ cog_translate (
931+ raster_path_rgba_nodata ,
932+ "cogeo.tif" ,
933+ cog_profiles .get ("deflate" ),
934+ quiet = True ,
935+ )
936+ assert cog_validate ("cogeo.tif" )
937+
938+ with rasterio .open ("cogeo.tif" ) as cog :
939+ assert cog .nodata is not None
940+ assert has_alpha_band (cog )
You can’t perform that action at this time.
0 commit comments