将numpy数组写入rasterio栅格文件会生成透明的tiff

时间:2018-09-17 16:44:37

标签: python raster tiff gdal rasterio

我正在使用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)

0 个答案:

没有答案