坐标系转换 tif_wgs84tomercator

import rasterio
from rasterio.warp import calculate_default_transform, reproject, Resampling

# 输入输出路径
src_path = r"F:\data.tif"
dst_path =r"F:\data_mercator.tif"

# 定义目标坐标系(Web墨卡托投影,EPSG:3857)
dst_crs = "EPSG:3857"

with rasterio.open(src_path) as src:
    # 计算目标投影的transform和尺寸
    transform, width, height = calculate_default_transform(
        src.crs, dst_crs, src.width, src.height, *src.bounds
    )

    # 创建输出文件元数据
    kwargs = src.meta.copy()
    kwargs.update({
        'crs': dst_crs,
        'transform': transform,
        'width': width,
        'height': height
    })

    # 创建目标文件并执行重投影
    with rasterio.open(dst_path, 'w', ** kwargs) as dst:  # 注意此处 U+200B 字符
        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.bilinear  # 双线性插值保持数据平滑
            )
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值