import rasterio
from rasterio.warp import calculate_default_transform, reproject, Resampling
from pyproj import CRS
src_path = r"F:\EGM08_gravity_data\EGM08_gravity_data.tif"
dst_path = r"F:\EGM08_gravity_data\EGM08_gravity_data_utm.tif"
# 自定义横向墨卡托投影(中央经线-45°,标准纬线70°N)
dst_crs = CRS.from_proj4("""
+proj=tmerc +ellps=WGS84 +lat_0=90 +lon_0=-45 +k=0.994
+x_0=2000000 +y_0=2000000 +units=m +no_defs
""")
with rasterio.open(src_path) as src:
transform, width, height = calculate_default_transform(
src.crs, dst_crs,
src.width, src.height,
*src.bounds,
densify_pts=100 # 加密计算点[5](@ref)
)
# 关键修改:添加BIGTIFF选项
kwargs = src.meta.copy()
kwargs.update({
'crs': dst_crs,
'transform': transform,
'width': width,
'height': height,
'compress': 'lzw',
'BIGTIFF': 'YES' # 启用大文件支持[9](@ref)
})
# 优化内存管理
with rasterio.open(dst_path, 'w', ** kwargs) as dst:
for i in range(1, src.count + 1):
reproject(
source=rasterio.band(src, i),
destination=rasterio.band(dst, i),
src_transform=src.transform,
src_crs=src.crs,
dst_transform=transform,
dst_crs=dst_crs,
resampling=Resampling.cubic_spline,
num_threads=4, # 启用多线程加速[4](@ref)
warp_mem_limit=512 # 限制单线程内存(单位MB)[6](@ref)
)