【问题标题】:Saving array as Geotiff using rasterio使用光栅将数组保存为 Geotiff
【发布时间】:2020-03-02 16:30:30
【问题描述】:

我有以下 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 数组具有相同的shape

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

知道这里有什么问题吗?我不完全理解错误的含义。

【问题讨论】:

    标签: python raster numpy-ndarray geotiff rasterio


    【解决方案1】:

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

    【讨论】:

    • 感谢您的提示。我已经在调查 np.transpose 选项,但你的回答明确地让我走上了正确的道路
    猜你喜欢
    • 1970-01-01
    • 2019-04-22
    • 2020-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    相关资源
    最近更新 更多