使用rasterio将数组另存为Geotiff

我有以下numpy数组:

supervised.shape
(1270,1847)

我正在尝试使用以下代码通过rasterio将其保存到GeoTIFF:

with rasterio.open('/my/path/ReferenceRaster.tif') as src:
    ras_meta = src.profile

with rasterio.open('/my/output/path/output_supervised.tif','w',**ras_meta) as dst:
    dst.write(supervised)

ras_meta在哪里:

{'driver': 'GTiff','dtype': 'float32','nodata': None,'width': 1847,'height': 1270,'count': 1,'crs': CRS.from_epsg(32736),'transform': Affine(10.0,0.0,653847.1979372115,-10.0,7807064.5603836905),'tiled': False,'interleave': 'band'}

我遇到以下我无法理解的错误,因为参考栅格和我的supervised数组都具有相同的shape

ValueError: Source shape (1270,1847) is inconsistent with given indexes 1

任何想法在这里是什么问题?我没有完全理解错误的含义。

a1025445866 回答:使用rasterio将数组另存为Geotiff

write需要一个形状为(band,row,col)的数组。您可以调整数组的形状,也可以使用write(supervised,indexes=1)

本文链接:https://www.f2er.com/3153920.html

大家都在问