使用rasterio将数组保存为Geotiff

9

我有以下的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,
       0.0, -10.0, 7807064.5603836905), 'tiled': False, 'interleave': 'band'}

我遇到了以下错误,我无法理解,因为参考栅格和我的"supervised"数组都具有相同的形状。
ValueError: Source shape (1270, 1847) is inconsistent with given indexes 1

有什么想法这里是什么问题?我并不完全理解错误的含义。
1个回答

7

write 要求一个形状为 (band, row, col) 的数组。你可以重塑你的数组,或者你可以使用 write(supervised, indexes=1)


谢谢你的提示。我已经在调查np.transpose选项,但是你的回答确实让我走上了正确的道路。 - GCGM

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接