GDAL实现遥感影像几何校正(配准)

def registration(input_path, out_path, top_left, bottom_right, ik, jk, srs):
    """
    基于python GDAL配准
    :param input_path: 需要配准的栅格文件
    :param out_path: 输出配准后的栅格文件位置
    :param top_left: 左上角坐标
    :param bottom_right: 右下角坐标
    :param ik: 行空白分辨率
    :param jk: 列空白分辨率
    :return:
    """
    # 打开栅格文件
    dataset = gdal.Open(input_path, gdal.GA_Update)
    # 获取图片的实际分辨率
    img = cv2.imread(input_path, 1)
    x, y = img.shape[1], img.shape[0]
    print('配准的左上角、右下角、x轴白边、y轴白边、像素x、像素y,坐标系', top_left, bottom_right, ik, jk, x, y, srs, type(srs))
    # 构造控制点列表 gcps_list
    gcps_list = [gdal.GCP(top_left[0], top_left[1], 0, 0, 0),
                 gdal.GCP(bottom_right[0], top_left[1], 0, x - jk, 0),
                 gdal.GCP(top_left[0], bottom_right[1], 0, 0, y - ik),
                 gdal.GCP(bottom_right[0], bottom_right[1], 0, x - jk, y - ik)]
    # 设置空间参考
    spatial_reference = osr.SpatialReference()
    if srs == 4528:
        spatial_reference.SetWellKnownGeogCS('CGCS2000')
    else:
        spatial_reference.ImportFromEPSG(srs)
    # 添加控制点
    dataset.SetGCPs(gcps_list, spatial_reference.ExportToWkt())
    # tps校正 重采样:最邻近法
    dst_ds = gdal.Warp(out_path, dataset, format='GTiff', tps=True, width=x, height=y,
                       resampleAlg=gdal.GRIORA_NearestNeighbour)

你可能感兴趣的:(GIS,gis,python)