Ok, so the clip_management allows me to use a feature class extent to clip the raster but it's still necessary to introduce the rectangle parameters (I thought that I could find something to substitute the rectangle by a feature class). Well, the initial purpose was to cut some rasters with a polygon feature class (administrative boundaries). The approach was first to extract single polygons to new feature classes and to use these to cut the rasters located in a specific folder. When I thought all was great I ran into an error: after extracting the single polygons to new shapefiles the clipping process is interupted by the following message: ERROR 000732: Output Extent: Dataset 1.shp does not exist or is not supportedFailed to execute (Clip).I attached a print screen of the error message.The script is the following:import arcgisscripting, os, string
gp = arcgisscripting.create()
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
gp.SetProduct("ArcInfo")
clip = "D:/hyperspectralImages/torrejon/torrejon_ALI/clip/clip.shp" #the polygon feature class
rows = gp.SearchCursor(clip)
row = rows.Next()
while row: # here I am extracting each polygon to an individual feature class
FID = row.GetValue("FID")
hoja = row.GetValue("hoja")
Expression = '\"FID\" = ' + str(FID)
outFeatures = "D://hyperspectralImages//torrejon//torrejon_ALI//outClips//"+str(hoja)+".shp" #the single fc's will be named after the field "hoja"
print "Extracting sheet number "+str(hoja) #like 1.shp, 2.shp...etc
gp.Select_analysis(clip,outFeatures,Expression)
row=rows.Next()
print "Finished extracting individual sheets.Begining to clip..."
inputFolder= "D:/hyperspectralImages/torrejon/torrejon_ALI/rasters" #the folder where all the rasters to be clipped are located
gp.Workspace = inputFolder
rasters = gp.ListRasters()
rasters.Reset()
raster = rasters.Next()
clipFeatures = "D://hyperspectralImages//torrejon//torrejon_ALI//outClips//" #the folder where the polygon feature classes used for clipping are located
while raster: # the loop to clip each raster by each polygon feature class
for feature in os.listdir(clipFeatures):
if feature.endswith(".shp"):
outRaster = "D://hyperspectralImages//torrejon//torrejon_ALI//output//"+feature[0:-3]+".tif"
print "Clipping "+raster+" with sheet number "+feature[0:-3]
gp.clip_management(raster,"446716,298473 4425996,437405 499153,348855 4492682,68626",outRaster,feature,"255","ClippingGeometry")
print "Done"
The 1.shp, 2.shp ..and so on do exist in the right folder...Do you have any idea of what's happening?Thanks,Bogdan