试图遍历我的文件夹(目录)中的每个tif图像

时间:2019-11-07 20:30:25

标签: python loops

试图遍历我的文件夹(即目录)中的每个tif图像,它可以打印,但似乎无法通过每个iamge运行该功能。我是python新手,所以将不胜感激

Result = []

def calculation_A(filename):
    data = gdal.Open(filename)

    band = data.GetRasterBand(1)
    arr = band.ReadAsArray()
    rows = len(arr)
    cols = len(arr[0])

    temp = []
    r_temp = []
    for i in range(rows):
        for j in range(cols):
            if arr[i][j] > -200:
                temp.append(arr[i][j])
                r_temp.append(np.asarray(temp).mean())
                r_temp.append(np.asarray(temp).min())
                r_temp.append(np.asarray(temp).max())
    return r_temp

directory = "C:/Users/valeria.briones/Desktop/New folder/Tmax"
for filename in os.listdir(directory):
    if filename.endswith(".tif"):
        print(filename)
        Result.append(calculation_A(filename))
print(Result) 

0 个答案:

没有答案