clipping multiple rasters to single polygon

617
2
02-28-2013 12:17 PM
ThomasHutchens
New Contributor
Hi,

So I have 44 individual polygons and then 50 raster datasets, and I would like to clip the single polygon to the 50 rasters and get 50 individual rasters in the extent of the polygon. I have been using the batch process but I would love to figure out how to automate the process better. I've tried modelbuilder; using the clip tool in conjunction with iterate rasters, but I only get one output, its my first time using iterate rasters in modelbuilder.

Any feedback will be much appreciated.

Dan
0 Kudos
2 Replies
CalebMackey1
Regular Contributor II
I think this would be easy in Python.  If all of your rasters are in the same folder you could just use the ListRasters to iterate through them all.  If not, you could use a wildcard and the os.walk or arcpy.da walk (for Arc 10.1) to loop thru folders.


import arcpy, os

arcpy.env.workspace = r'G:\WIU\Geog408\deng_lab4\Thermal_south_results\May\deg_170'
arcpy.env.overwriteOutput = True

# Clip region
poly = r'C:\testing\TestData\clipReg.shp'
out_folder = r'C:\testing\TestData\outputs'

for raster in arcpy.ListRasters():
    out_raster = os.path.join(out_folder,raster)
    arcpy.Clip_management(raster,'#',out_raster,poly,'#','ClippingGeometry')
    print 'Clipped: %s' %raster
0 Kudos
ThomasHutchens
New Contributor
well I'm not too experienced with python but I will give this a try, thanks so much for responding.

Dan
0 Kudos