python2.7 environment
without further ado, just upload the code
import arcpy
import os
arcpy.CheckOutExtension("spatial")
arcpy.gp.overwriteOutput = 1
arcpy.env.overwriteOutput=True
arcpy.env.workspace = "G:\\RF\\01_result\\tif" #shp文件所在地址
shps = arcpy.ListFiles("*.shp")
arcpy.env.workspace = "G:\\RF\\01_result\\tif" #tif文件所在地址
rasters = arcpy.ListRasters("*", "tiff")
for shp in shps:
mask = shp
print(mask)
catchment_name = 'china'
#
for raster in rasters:
print (raster)
if os.path.exists(r"G:\\RF\\01_result\\01_hu_result_tif"):#输出文件所在地址
out = (r"G:\\RF\\01_result\\01_hu_result_tif\\" + os.path.splitext(raster)[0] + ".tif")
else:
os.makedirs(r"G:\\RF\\01_result\\01_hu_result_tif")#输出文件所在地址
out = (r"G:\\RF\\01_result\\01_hu_result_tif\\" + os.path.splitext(raster)[0] + ".tif")
arcpy.gp.ExtractByMask_sa(raster, mask, out)
print("clip_"+raster+" has done")
print(catchment_name+"_Q_has done")
print("All done")
`
## tif转csv,CSV转tif,csv文件操作,tif文件操作,nc文件操作,机器学习XGBOOST,RF等看作者名字