Hi Neda,From my understanding, you first created a 2x2 fishnet shapefile for each raster in a directory. You now want to clip each one of those rasters by each polygon in the fishnet. If that is correct, take a look at the following code:import arcpy
from arcpy import env
env.workspace = r"C:\TIFFs"
env.overwriteOutput = 1
list = []
#append each raster to a list
lstFCs = arcpy.ListFeatureClasses("*")
for fc in lstFCs:
list.append(fc)
#iterate through each raster
lstRasters = arcpy.ListRasters("*")
for raster in lstRasters:
for n in list:
#find the fishnet shapefile by checking if the raster name is in the shapefile name
if raster.split(".")[0] in n:
rows = arcpy.SearchCursor(n)
for row in rows:
FID = row.FID
#create a feature layer for each polygon in the fishnet shapefile
arcpy.MakeFeatureLayer_management(n, "FC_lyr", "FID = " + str(FID))
#clip the raster by each polygon, and output a new TIFF to another directory
arcpy.Clip_management(raster, "#", r"C:\TIFFs\Clip" + "\\" + raster + "_clip_" + str(FID) + ".tif", "FC_lyr", "256", "ClippingGeometry")
print "Finished"
Also, a quick note, when you are posting code, be sure to wrap it in CODE tags using the # symbol above. This will preserve the indentation. I believe you were previously wrapping the code with QUOTE tags.