批量归一化遥感栅格数据
python代码:
# -*- encoding:utf-8 -*-
import sys # reload()之前必须要引入模块
reload(sys)
sys.setdefaultencoding('utf-8')
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
# 这个是工作空间目录,待处理的所有影像都在这个文件型数据库中
env.workspace = r"D:\VPD-SM-SIF\0new\2003-2019\1kmVPD"
# 设置读取的栅格类型,可以参考ArcGIS的官方文档,下面的是读取目录下所有类型的栅格文件
rasterList = arcpy.ListRasters("*")
# 结果输出文件夹
out_path = r"D:\VPD-SM-SIF\0new\2003-2019\NVPD\\"
for raster in rasterList:
print(raster)
inRaster = raster
maxValueDS = arcpy.GetRasterProperties_management(inRaster, "MAXIMUM")
maxValue = maxValueDS.getOutput(0)
print("最大值:" + str(maxValue))
minValueDS = arcpy.GetRasterProperties_management(inRaster, "MINIMUM")
minValue = minValueDS.getOutput(0)
print("最小值:" + str(minValue))
NormalizationRaster = (Raster(inRaster) - float(minValue)) / (float(maxValue) - float(minValue))
out = out_path + inRaster
NormalizationRaster.save(out)
print('finish:' + out)