-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBatch_Sum.py
53 lines (42 loc) · 1.34 KB
/
Batch_Sum.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# coding:utf-8
import glob
import arcpy
from arcpy import env
import os
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
arcpy.gp.overwriteOutput = 1
inpath = r'F:\sum_1110\RNEP' #输入路径
outpath = r'E:\陈星师姐\2\NEP_10y_Mean'
# Press the green button in the gutter to run the script.
styear = 2000
edyear = 2018
character = 'NPP_*.tif'
def Sum(indir,outdir,character):
Sum = 0
arcpy.env.scratchWorkspace = indir + os.sep
env.workspace = indir + os.sep #设置工作空间
List = arcpy.ListRasters(character)
if len(List) == 0:
print('{} length is {}'.format(indir, len(List)))
return 0
for data in List:
print('Data: {} '.format(data))
try:
Sum += Raster(str(data)) # 相加
except RuntimeError:
print('{} is error continue'.format(data))
continue
if not os.path.exists(outdir):
os.makedirs(outdir)
print('{} is create ok!!!!!!'.format(outdir))
(Sum).save(outdir + os.sep + 'Sum_' + indir + '.tif')
print(outdir + ' is ok ')
return 1
for year in range(styear,edyear+1):
dir = inpath + os.sep + str(year)
outdir = outpath + os.sep + str(year)
Sum(dir,outdir,character)
print(outdir + ' is ok ')
print('ALL is ok !!!!!!!!!!!')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/