gdal实现影像重采样至高分辨率(30m->15m)
'''
Created on 2020年5月21日
@author: wjshen
'''
from osgeo import gdal
import os
path=r"D:\test"
os.chdir(path)
in_ds=gdal.Open("p122r043.tif")
in_band=in_ds.GetRasterBand(1)
xsize=in_band.XSize
ysize=in_band.YSize
geotrans=list(in_ds.GetGeoTransform())
geotrans[1]/=2#像元宽度变为原来的0.5倍
geotrans[5]/=2#像元高度变为原来的0.5倍
#重采样后的影像
if os.path.exists('resampled.tif'):#如果已存在同名影像
os.remove('resampled.tif')#则删除之
out_ds=in_ds.GetDriver().Create('resampled.tif',xsize*2,ysize*2,1,in_band.DataType)#创建一幅重采样后的影像的句柄,行列数都变成原来的2倍
out_ds.SetProjection(in_ds.GetProjection())#设置投影坐标
out_ds.SetGeoTransform(geotrans)#设置地理变换参数
data=in_band.ReadAsAr