全部自动化批量处理,当然右键batch也可以处理,但是一旦有上百个文件,那就运动手指了。
代码如下,注释都有,根据需要改动参数即可。
import arcpy
# Set the current workspace
arcpy.env.workspace = ("F:/ZPATR-TIME-JOB/ndvi-china-/") # "D:\\Test2\\Grids.gdb"
# Polygon Shapefiles Workspace
clipFeatures = ('F:/ZPATR-TIME-JOB/ndvi-china-/shp/xinjiang.shp/') # "D:\\Test2\\Shps\\"
# Output Directory
outDirectory = ('F:/ZPATR-TIME-JOB/ndvi-china-/xinjiang/') # "C:\\Users\\sgraf\\Documents\\ArcGISData\\Test2\\Outs.gdb\\"
# Get and print a list of GRIDs from the workspace
rasters = arcpy.ListRasters("*", "TIF")
for raster in rasters:
arcpy.AddMessage("Clipping " + raster + " with " + raster + ".shp")
desc = arcpy.Describe(clipFeatures + "\\" + raster + ".shp")
extent = desc.extent
arcpy.Clip_management(raster, str(extent), outDirectory + "\\" + raster, clipFeatures + "\\" + raster + ".shp", "#",
"ClippingGeometry", "NO_MAINTAIN_EXTENT")