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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.