Python 光栅为每个波段设置一个唯一的名称
我有一个形状数组Python 光栅为每个波段设置一个唯一的名称,python,rasterio,Python,Rasterio,我有一个形状数组(b,N,M),它有b条带或大小为nxm的图像。我可以使用以下方法将它们写入多波段.tiff文件: band_nums=范围(1,b+1) 将rasterio.open(文件路径'w',**元数据)作为dst: dst.write(数组、索引=带数) 我需要做的是为每个乐队设定一个名字。目前,它设置默认名称为Band\u 0、Band\u 1、…、Band\u b您可以使用set\u description方法: with rasterio.open( '.your_
(b,N,M)
,它有b
条带或大小为nxm
的图像。我可以使用以下方法将它们写入多波段.tiff
文件:
band_nums=范围(1,b+1)
将rasterio.open(文件路径'w',**元数据)作为dst:
dst.write(数组、索引=带数)
我需要做的是为每个乐队设定一个名字。目前,它设置默认名称为
Band\u 0、Band\u 1、…、Band\u b
您可以使用set\u description
方法:
with rasterio.open(
'.your_file.tif',
'w',
driver='GTiff',
height=height,
width=width,
count=2,
dtype=dtype,
crs=crs,
transform=transform,
) as dst:
dst.write(band_1, 1)
dst.set_band_description(1, 'Band 1 Name')
dst.write(band_2, 2)
dst.set_band_description(2, 'Band 2 Name')
否则,正如您所建议的,此解决方案同样有效:
dst.descriptions = tuple(['Band 1 name', 'Band 2 name', 'Band 3 name'])
谢谢你的回复<代码>设置\u波段\u说明在我的案例中不存在。受您答案的启发,我将其修改为
dst.descriptions=tuple(['Band1 name','Band2 name','Band3 name')
。如果你确定你的答案,我可以接受。完成!这样做也很好