Skip to main content
 首页 » 编程设计

python之栅格写入 GeoTiff 时缺少空间引用

2024年10月01日8zengkefu

我正在尝试使用 rasterio 加载图像,修改 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)。在不了解更多关于您的安装/操作系统的情况下,我不能肯定地说,但是如果 gdal(和 rasterio)无法找到元数据文件的位置,例如那些支持涉及坐标引用系统的操作,您将在输出 tif 中丢失 CRS。