通常,我們需要將多個柵格求平均,例如,將一年中每個月的NDVI值加起來除以12,就會等到月均NDVI,該程序雖然在柵格計算器中可以實作,但是當時間序列較長時就比較費事,此時,python代碼是不二的選擇,
下圖所示為柵格資料相加的原理圖,也就是對應的柵格相加,生成新的柵格資料,求均值是需要再除以柵格個數,

在獨立腳本中撰寫如下代碼:

python求均值代碼友情贈送:
import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("spatial")
arcpy.gp.overwriteOutput=1
#custom
arcpy.env.workspace="G:\\Phenology of 30 Years\\GIMMS 3g\\15Length\\1Length\\"
#custom
outpath="G:\\Phenology of 30 Years\\GIMMS 3g\\15Length\\2mean_len\\"
#custom
outfilename="mean";n=30;
Sum=0
files=arcpy.ListRasters()
for file in files:
Sum=Sum+Raster(file)
(Sum/n).save(outpath+outfilename)
print("Done,please close")
CSDN認證博客專家
GIS專家
GIS研發工程師
優秀指導教師
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/200723.html
標籤:python
