I tried to fuse 4 multispectral bands from Landsat 8 with resampled SRTM, Aspect, Slope. It should contain 7 bands: R,G,B,NIR,DEM,Aspect,Slope. The code execution generates output raster, MS bands are ok, while DEM,Aspect and Slope are empty. Code results an error. What is wrong?

import rasterio
import numpy as np

file_list = ['E:/Burabay2019/SpaceImages/Calculated/LC08_L1TP_156023_20150626_20170407_01_T1_clip/LC08_L1TP_156023_20150626_20170407_01_T1_B4_c.TIF',

with rasterio.open(file_list[1]) as src0:
   meta = src0.meta
meta.update(count = len(file_list))
with rasterio.open('E:/Burabay2019/SpaceImages/Calculated/datafusion_LC08_L1TP_156023_20150626_dem_20190728.TIF', 'w', **meta) as dst:
for id, layer in enumerate(file_list, start=1):
    with rasterio.open(layer) as src1:
        dst.write_band(id, src1.read(1))

The error is below:

ValueError                                Traceback (most recent call last)
<ipython-input-2-e20e01c8ca7c> in <module>
 24     for id, layer in enumerate(file_list, start=1):
 25         with rasterio.open(layer) as src1:
 ---> 26             dst.write_band(id, src1.read(1))
 rasterio\_io.pyx in rasterio._io.DatasetWriterBase.write_band()
 rasterio\_io.pyx in rasterio._io.DatasetWriterBase.write()
 ValueError: the array's dtype 'float32' does not match the file's dtype 'uint16'
  • You need to convert all of your tiff images to the same bit depth (e.g. uint16 or float32) – Aaron Jul 28 '19 at 1:27
  • Thank you, I forgot that Aspect and Slope map are float data. I'll report the results. – Edu Gis Jul 28 '19 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.