栅格写入 GeoTiff 时缺少空间参考

Spatial reference missing from rasterio write to GeoTiff

我正在尝试使用光栅加载图像,修改 ndarray,然后使用与原始图像相同的空间参考系统写出。下面的函数是我尝试这样做的。但是输出的 geotiff 中缺少空间参考系统。对我做错了什么有什么建议吗?

我已检查输入的 geotiff crs 是否有效 ('epsg:32611')。

# Function to write out an ndarry as a GeoTIFF using the spatial references of a sample geotif file
def write_GeoTif_like(templet_tif_file, output_ndarry, output_tif_file):
    import rasterio
    orig = rasterio.open(templet_tif_file)
    with rasterio.open(output_tif_file, 'w', driver='GTiff', height=output_ndarry.shape[0],
                       width=output_ndarry.shape[1], count=1, dtype=output_ndarry.dtype,
                       crs=orig.crs, transform=orig.transform, nodata=-9999) as dst:
        dst.write(output_ndarry, 1)

以前被这个问题困扰过,我猜你的 GDAL_DATA 环境变量设置不正确(有关详细信息,请参阅 https://github.com/conda/conda/issues/4050)。在不了解您的 installation/OS 的情况下,我不能肯定地说,但是如果 gdal(和 rasterio)无法找到元数据文件的位置,例如那些支持涉及坐标参考的操作的文件系统,您将在输出 tif 中丢失 CRS。