光栅源形状与给定索引1不一致

2024-09-29 07:23:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要保存一个3波段的geotiff文件。我目前正在使用rasterio,当我写出3波段图像时,我得到了错误Source shape (1, 3445, 4703, 4) is inconsistent with given indexes 1。在

我的最终目标是能够对图像执行一些分析并将其写入文件。在

我已经试过reshape_as_rasterreshape_as_image。我也尝试过其他一些组合。转置(arr,(0,1,2))

https://rasterio.readthedocs.io/en/stable/topics/image_processing.html#imageorder

with rio.open(r"C:\Users\name\Documents\project\name.tif") as src:
naip_data = src.read()
naip_meta = src.profile

image = reshape_as_raster(naip_data)

with rio.open('C:\\Users\\name\\Documents\\UAV_test_save\\filename.tif',     'w',**naip_meta) as dst:
        dst.write(image, 3)

我希望在文件中保存一个geotiff。相反,我得到:

ValueError rasterio_io.pyx in rasterio._io.datasetWriterBase.write()

ValueError: Source shape (1, 3445, 4, 4703) is inconsistent with given indexes 1


Tags: 文件nameio图像imagesrcsourceas