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
python 计算tif图像四个角的经纬度坐标
最新推荐文章于 2024-12-30 21:07:59 发布