I have a single raster file and about 40 small polygons shapes. I would like to clip the raster by the extent of all these shapes, and create 40 resulting .img files.
I know I can just do this by right-clicking the clip tool and selecting batch process.... but I would rather have a script because I will need to do this multiple times over the next few months.
I am inexperienced in python and would like some help with my script. I am not using geodatabases, just a simple input and output folder. I was looking at a similar post which has the below code... but the rectangle number option in arcpy.Clip_management requires me to manually enter every single rectangle number which defeats the purpose for me.
How can I modify this to manually clip a single raster using all 40 polygon files?
I am using ArcGIS 10.2.2.
import arcpy rasterlist = arcpy.ListRasters("your_workspace") for raster in rasterlist: for i in range(40): arcpy.MakeFeatureLayer_management("your_shapefile", "layer" + str(i), ' "FID" = ' + str(i)) #create a layer with only polygon i arcpy.Clip_management(raster, "#", raster[:-4] + "clip" + str(i) +" .img","layer" + str(i), "0", "ClippingGeometry") #clip based on layer, clipping geometry will use the polygon extent only