Friday, April 6, 2012

Snippet: Add a Spatial Index To All Feature Classes

Ever need to run a batch spatial index in a work space? Yes, well here is a snippet to help you out. import arcpy
from arcpy import env

env.workspace = arcpy.GetParameterAsText(0) # workspace parameter
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
   arcpy.AddSpatialIndex_management(fc)
print 'fin'
Enjoy

2 comments:

Shane P said...

Typically, I'd design the script to pull in all the feature layers in a list, then run through those.

I noticed you pull everything in from the workspace and run through it in your loop instead. I never tried that before. Nice tip!

Pål Herman said...

Hm, isnt it exactly what is happening? Making list fcs, "for-looping" with building spatial index.

First visit to this blog, great resource