I have multiple shapefiles in a folder and I want to intersect all of them which overlap. So far I am making two lists and overlapping all of the possible file combinations (I am using a cartesian list in this example, although in hindsight I think I could have skipped that step).
I am using this code:
import arcpy, os, itertools arcpy.env.workspace=r'F:\Sheyenne\fire\split_fire' shapefiles=[os.path.join(arcpy.env.workspace, i) for i in arcpy.ListFeatureClasses('*.shp')] shapefiles2=[os.path.join(arcpy.env.workspace, i) for i in arcpy.ListFeatureClasses('*.shp')] #same shapefiles but used to find the file combinations out=r'F:\Sheyenne\fire\intersects' if not os.path.isdir(out): os.mkdir(out) result = list(itertools.product(shapefiles,shapefiles2)) for files in result: x=(files) y=(files) for i in x: outname=x.split('\\')[-1].split('.') + '_' + y.split('\\')[-1] arcpy.Intersect_analysis([x, y], os.path.join(out,outname)) print "Done"
This will intersect all the possible combinations, but since there are so many combinations it is extremely slow (the majority don't overlap), I am thinking there is a faster way to determine which ones instersect in the first place and then only instersect those ones. My code above also doesn't deal with the fact that more than 2 shapefiles can overlap.