import rasterio
已有正确地理信息的影像
ref_file = r"D:\20220104T172343_truth.tif"
需要添加地理信息的影像
input_file = r"D:\validation\truthimage\20220104T172343_truth.tif"
输出文件
output_file = r"D:\mission\validation\truthimagegeo\20220104T172343_truth.tif"
读取参考影像信息
with rasterio.open(ref_file) as ref:
ref_profile = ref.profile
ref_crs = ref.crs
ref_transform = ref.transform
读取需要添加地理信息的影像
with rasterio.open(input_file) as src:
data = src.read()
profile = src.profile
替换地理信息
profile.update(
crs=ref_crs,
transform=ref_transform
)
保存
with rasterio.open(output_file, "w", **profile) as dst:
dst.write(data)
print("完成:", output_file)