python 计算tif图像四个角的经纬度坐标

from osgeo import gdal
def calculate(tif_path,comboxIndex):
    dataset = gdal.Open(tif_path + "/" + os.listdir(tif_path)[comboxIndex])  # 打开tif
    geo_information = dataset.GetGeoTransform()
    col = dataset.RasterXSize  # 行数
    row = dataset.RasterYSize  # 列数
    # band = dataset.RasterCount  # 波段

    top_left_corner = [0, 0]  # 左上角
    bottom_left_corner = [col, 0]  # 左下角
    top_right_corner = [0, row]  # 右上角
    bottom_right_corner = [col, row]  # 右下角

    # 左上角经纬度
    top_left_corner_lon = geo_information[0] + top_left_corner[0] * geo_information[1] + top_left_corner[1] * geo_information[2]
    top_left_corner_lat = geo_information[3] + top_left_corner[0] * geo_information[4] + top_left_corner[1] * geo_information[5]

    # 左下角经纬度
    bottom_left_corner_lon = geo_information[0] + bottom_left_corner[0] * geo_information[1] + bottom_left_corner[1] * geo_information[2]
    bottom_left_corner_lat = geo_information[3] + bottom_left_corner[0] * geo_information[4] + bottom_left_corner[1] * geo_information[5]

    # 右上角经纬度
    top_right_corner_lon = geo_information[0] + top_right_corner[0] * geo_information[1] + top_right_corner[1] * geo_information[2]
    top_right_corner_lat = geo_information[3] + top_right_corner[0] * geo_information[4] + top_right_corner[1] * geo_information[5]

    # 右下角经纬度
    bottom_right_corner_lon = geo_information[0] + bottom_right_corner[0] * geo_information[1] + bottom_right_corner[1] * geo_information[2]
    bottom_right_corner_lat = geo_information[3] + bottom_right_corner[0] * geo_information[4] + bottom_right_corner[1] * geo_information[5]
    return top_left_corner_lon,top_left_corner_lat,bottom_left_corner_lon,bottom_left_corner_lat,top_right_corner_lon,top_right_corner_lat,bottom_right_corner_lon,bottom_right_corner_lat

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zhichao_97

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值