-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBatch_Con.py
42 lines (33 loc) · 1.05 KB
/
Batch_Con.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
# coding:utf-8
import glob
import arcpy
from arcpy import env
import os
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
arcpy.gp.overwriteOutput = 1
def SetNodata(indir,outdir,character):
arcpy.env.scratchWorkspace = indir + os.sep
env.workspace = indir + os.sep
List = arcpy.ListRasters(character)
if len(List) == 0:
return 0
for data in List:
print(data)
OutRas = Con(IsNull(Raster(data)),0,Raster(data))
OutRas.save(outdir + os.sep + 'Con_' + data)
return 1
path = {
r'E:\Integrated_analysis_data\Data\Vertify_out\Bagging_forest':'Bagging*.tif'}
styear = 2000
edyear = 2017
for inpath in path:
print(inpath)
character = path[inpath]
for year in range(styear, edyear + 1):
indir = inpath + os.sep + str(year)
outdir = indir
result = SetNodata(indir,outdir,character)
print('-------Finish--------' if result==1 else '-------{} is Empty--------'.format(indir))
print('{} is ok '.format(year))
print('{} is ok !!!!!'.format(inpath))