I am new to scripting.
I have around 4500 small shapefiles to be intersected with one big shapefile. The primary key is to make 4500 small intersected shapefiles.
How to do it correctly by using ArcPy?
I tried using batch processing, but I quit after few tries, as it is lot of work. I wrote some kind of "script".
#system modules
import arcpy, os, datetime
from arcpy import env
from arcpy.sa import *
arcpy.env.workspace = r"D:\test\split\los"
arcpy.env.overwriteOutput = True
print "start"
infeature = ["big.shp", "small1.shp"]
join_attributes = "ALL"
cluster_tolerance = "-1 Unknown"
output_type = "INPUT"
for i in infeature:
outfeature = r"D:\test\split\los_" + i
arcpy.Intersect_analysis(infeature, outfeature, join_attributes, cluster_tolerance, output_type)
print "end"
Vince
20.5k16 gold badges49 silver badges65 bronze badges
-
List the 4500 shapefiles using listfeatureclasses. How are they named?Bera– Bera2020年04月15日 18:47:29 +00:00Commented Apr 15, 2020 at 18:47
-
Shapefiles are called 1.shp, 2.shp, 3.shp etc.Adam– Adam2020年04月15日 18:49:35 +00:00Commented Apr 15, 2020 at 18:49
1 Answer 1
Try to use ListFeatureClasses:
Returns a list of the feature classes in the current workspace
Untested:
import arcpy, os, datetime
from arcpy import env
arcpy.env.workspace = r"D:\test\split\los"
arcpy.env.overwriteOutput = True
smallshapes = [f for f in arcpy.ListFeatureClasses() if f.split('.')[0].isdigit()] #List all shapefiles that have only digits in name
join_attributes = "ALL"
cluster_tolerance = "-1 Unknown"
output_type = "INPUT"
i = 0 #For naming outputs
for smallshape in smallshapes:
outfeature = r"D:\test\split\los_" + "{0}.shp".format(i)
arcpy.Intersect_analysis([smallshape, "big.shp"], outfeature, join_attributes, cluster_tolerance, output_type)
i+=1
print "end"
answered Apr 15, 2020 at 18:55
lang-py