我正在使用Rasterio从Sentinel 2中读取GeoTIFF并计算NDVI,但是当我尝试另存为新的TIF文件时,该文件将变成透明图像。我想念什么?
那是代码:
class MapService:
def __init__(self):
dsRed = rasterio.open('data/bands/B04.TIF')
bandRed = dsRed.read(1)
dsNIR = rasterio.open('data/bands/B08.TIF')
bandNIR = dsNIR.read(1)
ndvi = np.zeros(dsRed.shape, dtype=rasterio.float32)
ndvi = (bandNIR.astype(float)-bandRed.astype(float))/(bandNIR+bandRed)
kwargs = dsRed.meta
kwargs.update(
dtype=rasterio.float32,
count=1,
compress='lzw')
self.ndvi = ndvi
with rasterio.open('result/example-total.tif', 'w', **kwargs) as dst:
dst.write(ndvi.astype(rasterio.float32),1)