#按掩膜提取数据
import arcpy
from arcpy import env
from arcpy.sa import *
import os
import os.path
import sys
rootdir = 'D:\\clime21'
filenames = os.listdir(rootdir)
for filename in filenames:
if os.path.splitext(filename)[1] == '.tif':
inRaster = rootdir + os.sep + filename
outname = filename[28:44]
# outname = myname.replace('.tif')
inMaskData = "D:\\ChinaDEM\\ChinaDEM.tif"
arcpy.CheckOutExtension("Spatial")
outExtractByMask = ExtractByMask(inRaster, inMaskData)
#
print "ok"
outExtractByMask.save("D:\\xh\\" + outname + '.tif')