- 说明:本人这是刚入门时学的 python和arcgis,由于快要毕业啦,不管好不好用,反正当初是实现了我要的功能,虽然现在回头看下确实比较烂,但是作为一种经验,也就放出来啦,毕业就转行了,这里就当做是一个留念吧。
import arcpy
from arcpy.sa import *
path = "G:/GEE/spartinaWater" # 工作路径
arcpy.env.workspace = path
rasters = arcpy.ListRasters("*0.tif", "tif")
arcpy.CheckOutExtension("Spatial")
inMaskDataAll = ["site4_20171231_20180931.tif"]
for inMaskData in inMaskDataAll: 由于我需要裁剪的不仅是 2 个掩模,所以用了两个 for 循环
for inRaster in rasters:
ractByMask = ExtractByMask(inRaster, inMaskData) # 裁剪的工具
ractByMask.save(path+'/'+str(inMaskData)[:5]+'_'+inRaster[:25]+'.tif')
print(inRaster)
2.下面是利用 Resample_management 批量进行重采样的工具
rasters = arcpy.ListRasters("site*", "tif")
for inRaster in rasters:
arcpy.Resample_management(inRaster, path+'/'+inRaster[:-4]+'_re.tif',
"20171002R2.tif", "CUBIC")