如何选择在使用Python Rioxarray重新投影时不更改图像大小?

问题描述 投票:0回答:1

我在坐标系 EPSG:4326 中有一个大小为 18346x10218 的 tif 格式的图像,我想将其转换为新的坐标系,我使用 Python 中的 rioxarray 使用以下方法来完成此操作。

import rioxarray

rast_path = "old_projection.tif"

rds = rioxarray.open_rasterio(rast_path)
rds_3996 = rds.rio.reproject("EPSG:3996")
rds_3996.rio.to_raster("new_projection.tif")

这会将 tif 文件保存在新投影中,但我注意到它将图像大小增加到 20198x20198。当我打开文件时,新像素不可见,因此我假设它们不包含任何数据,但文件的大小增加了一倍多。有没有办法以这种方式重新投影数据而不保存空像素?感谢您的帮助!

python raster python-xarray projection epsg
1个回答
0
投票

尝试这样

import rioxarray

rast_path = "old_projection.tif"
rds = rioxarray.open_rasterio(rast_path)
# Specify the destination CRS (EPSG:3996) and use 'nearest' resampling
rds_3996 = rds.rio.reproject("EPSG:3996", resampling='nearest')
# Save the reprojected raster
rds_3996.rio.to_raster("new_projection.tif")
© www.soinside.com 2019 - 2024. All rights reserved.