I have about 400 rasters that I want to clip each of them based on a polygon object.
The code I tried to use is the following:
import arcpy, os
origpath = ur'd:\test'
jpgs = [f for f in os.listdir(origpath) if f.endswith('.jpg') and os.path.isfile(os.path.join(origpath,f))]
for jpg in jpgs:
r = arcpy.sa.Raster(os.path.join(origpath,jpg))
p = arcpy.Polygon(arcpy.Array([arcpy.Point(562879.802,4538631.518),arcpy.Point(583906.505,4538842.192),arcpy.Point(584139.129,4518489.715),arcpy.Point(563054.256,4518279.244)]))
arcpy.Clip_management(r,p,os.path.join(origpath,'clipped_'+jpg),'#','#','ClippingGeometry')
When it runs it produces an error:
ERROR 000628: Cannot set input into parameter rectangle.
I assume that it has to do with the Polygon Object, I have inserted, for the Extent parameter.
The last solution would be to put this one polygon in a feature class and then add this feature class as the extent parameter.
Is there any direct way to use the Polygon Object to clip my rasters?