Batch Clipping in ArcGIS Desktop using ArcPy?

The following script clips polygon watersheds to polygon county boundaries, naming each output featureclass something like HspWBD_HU12_county name. Tested and it works. Make sure your values in the NAME field have no special characters or spaces (simple Python string methods can clean that up for you).

import arcpy

arcpy.env.workspace = r'D:\Projects\GDBs\slowbutter.gdb\IPAS'
rows = arcpy.SearchCursor('HspAOI')
for row in rows:
    feat = row.Shape
    arcpy.Clip_analysis('HspWBD_HU12', feat, 'HspWBD_HU12_' + str(row.getValue('NAME')), '')

As you use ArcGIS 10, i would use modelbuilder with builtin tool: Iteration Feature Selection to perform this task. See the pseudo-model in the picture. it does not need to know python scritping at all. pseudo model


This sounds exactly like what the Split tool from the Analysis toolbox does.

However, it requires an ArcInfo license to run so is not available to the majority of ArcGIS Desktop users so I like Chad's answer which will work for ArcGIS 10 Desktop users with ArcView and ArcEditor level licenses too.