1

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
asked Apr 15, 2020 at 18:37
2
  • List the 4500 shapefiles using listfeatureclasses. How are they named? Commented Apr 15, 2020 at 18:47
  • Shapefiles are called 1.shp, 2.shp, 3.shp etc. Commented Apr 15, 2020 at 18:49

1 Answer 1

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.