Hello ESRI community,
I have a large raster that covers many farm fields. I would like to iterate through a feature class and clip the raster by each farm field polygon in the feature class. Originally I tried to do this in the Python window of ArcPro, but couldnt get ListRasters to work with the listMaps class. So, I am on to a stand-alone python script.
I keep getting an error when I run the code below. Clip_management wants four points to define the clipping rectangle but I specify a polygon geometry ('SHAPE@'). Im assuming that is the problem, but Im not sure how to fix it.
arcpy.env.workspace = r'C:\GIS\Data\10000_VGF\VGF_Satellite_Imagery\VGF_Satellite_Imagery.gdb'
out_loc = r'C:\GIS\Data\10000_VGF\VGF_Satellite_Imagery\VGF_Imagery_NDVI.gdb'
raster = arcpy.ListRasters('Imagery_merged_2021')[0]
farm = r'C:\GIS\Data\10000_VGF\VGF_Field_Boundaries\VGF_Field_Boundaries.gdb\VGF_Field_Boundaries'
fields = ['SHAPE@', 'Field_Name2', 'Farm']
where_clause = "Farm = 'VGF'"
i = 0
with arcpy.da.SearchCursor(farm, fields, where_clause) as cursor:
for row in cursor:
i = +1
arcpy.Clip_management(raster, row[1], out_loc + '\\' + row[2] + "_"+ str(i) + "_2021_clip", in_template_dataset = row[0], clipping_geometry = "ClippingGeometry") #clip based on layer, clipping geometry will use the polygon extent only