add_alpha=False means never add an alpha band, default is None

Resolves #1372
This commit is contained in:
Sean C. Gillies 2018-06-12 16:27:07 -06:00
parent 73ca8cfe6f
commit b5ff28add1
2 changed files with 18 additions and 4 deletions

View File

@ -649,7 +649,7 @@ cdef class WarpedVRTReaderBase(DatasetReaderBase):
src_nodata=None, dst_nodata=None, nodata=None,
dst_width=None, width=None, dst_height=None, height=None,
src_transform=None, dst_transform=None, transform=None,
init_dest_nodata=True, add_alpha=False, **warp_extras):
init_dest_nodata=True, add_alpha=None, **warp_extras):
"""Make a virtual warped dataset
Parameters
@ -699,8 +699,9 @@ cdef class WarpedVRTReaderBase(DatasetReaderBase):
-----
When the source dataset has an internal bitmask or sidecar .msk
file and no nodata value and no nodata value is specified for
the warped VRT, the `add_alpha` parameter will be set internally
to True so that a mask can be computed for the VRT.
the warped VRT, *and* `add_alpha` is None, the `add_alpha`
parameter will be set internally to True so that a mask can be
computed for the VRT.
Returns
-------
@ -857,7 +858,7 @@ cdef class WarpedVRTReaderBase(DatasetReaderBase):
# If the source dataset has a per-dataset mask and no dst_nodata
# value is specified, we need to specify that an alpha band is
# to be added to the VRT.
if MaskFlags.per_dataset in self.src_dataset.mask_flag_enums[0] and self.dst_nodata is None:
if MaskFlags.per_dataset in self.src_dataset.mask_flag_enums[0] and self.dst_nodata is None and self.dst_alpha is None:
self.dst_alpha = True
psWOptions = create_warp_options(

View File

@ -253,3 +253,16 @@ def test_add_alpha_read(path_rgb_byte_tif):
assert vrt.count == 4
assert vrt.colorinterp[3] == ColorInterp.alpha
data = vrt.read(boundless=True, window=Window(-200, -200, 1000, 1000), out_shape=((3, 600, 600)))
def test_default_add_alpha_read(path_rgb_msk_byte_tif):
"""An alpha band is added if add_alpha is unspecified and source has .msk"""
with rasterio.open(path_rgb_msk_byte_tif) as src, WarpedVRT(src) as vrt:
assert vrt.count == 4
assert vrt.colorinterp[3] == ColorInterp.alpha
def test_no_add_alpha_read(path_rgb_msk_byte_tif):
"""An alpha band is not added if add_alpha=False"""
with rasterio.open(path_rgb_msk_byte_tif) as src, WarpedVRT(src, add_alpha=False) as vrt:
assert vrt.count == 3