同一位置的两张tif影像,坐标系相同,像素大小相同,像素未完全对齐解决办法

0 阅读1分钟

在envi中打开同一位置处的两张tif影像,坐标系(Coordinate System)相同,像素大小(15m)相同, 彩色像素点(CH_AGB_15m.tif)与暗色像素点(Layer_Stack_Result_Resampled_to_15m.tif)不能完全重叠,如图所示: image.png 使用osgeo.gdal.Warp()解决:

from osgeo import gdal

reference = "Layer_Stack_Result_Resampled_to_15m.tif"
source = "CH_AGB_15m.tif"
output = "CH_AGB_15m_aligned.tif"

ref_ds = gdal.Open(reference)
gt = ref_ds.GetGeoTransform()

xmin = gt[0]
ymax = gt[3]
xmax = xmin + gt[1] * ref_ds.RasterXSize
ymin = ymax + gt[5] * ref_ds.RasterYSize

gdal.Warp(
    output,
    source,
    format='GTiff',
    dstSRS=ref_ds.GetProjection(),
    width=ref_ds.RasterXSize,
    height=ref_ds.RasterYSize,
    outputBounds=(xmin, ymin, xmax, ymax),
    resampleAlg=gdal.GRA_NearestNeighbour
)
ref_ds = None

效果如下: image.png

CH_AGB_15m_aligned.tif确实往下移动了: image.png