ArcPy – Batch Clipping in ArcGIS Desktop

arcgis-10.0arcgis-desktoparcpybatchclip

I've come across a few similar questions for older versions of ArcGIS, but haven't found a suitable answer for ArcGIS 10.

I have two polygon shapefiles that cover a large area (e.g. an entire State/Province). The first shapefile represents land cover for the entire State and the second represents 50 individual watersheds. I would like to clip the land cover shapefile based on each watershed (each has a unique name stored in a field). I would then like to save the output clipped files (one for each of the 50 watersheds) using the watershed name.

Given that there are 50 clips to be performed this process is a great candidate for batch processing.

Best Answer

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')), '')
Related Question