rasterio写入GeoTiff时缺少空间参考信息。

3

我正在尝试使用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)
1个回答

2
被这个问题咬过的经验告诉我,我猜测你的GDAL_DATA环境变量没有正确设置(更多细节请参见https://github.com/conda/conda/issues/4050)。我无法确定你的安装/操作系统的详细信息,但如果gdal(和rasterio)无法找到元数据文件所在的位置,例如支持涉及坐标参考系统的操作,那么输出tif文件中将丢失CRS。

在 Windows 上,GDAL_DATA 没有设置。手动设置后可以正常工作。我很惊讶的是,在 GDAL_DATA 未设置时,rasterio 没有抛出任何警告。 - nicway
是的,那是一个很好的观点。我还没有研究过实现它有多难。 - jdmcbr

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