I am looking for a way to split a feature class into multiple feature classes based on the number of records, probably using python. E.g first 100, next 100, etc. I have so far only seen options to split by attributes.
The following code will split the features into groups of 100 (or the value set in
outputNum) then copy them to individual feature classes.
import arcpy outputNum = 100 outputFCName = "OutputFC" def listSplit(myList, n): for i in xrange(0, len(myList), n): yield myList[i:i + n] arcpy.env.workspace = r"c:\gis\se\gisse.gdb" lyr = arcpy.mapping.Layer("RandomPoints") arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION") fList = list() with arcpy.da.SearchCursor(lyr, "OID@") as cursor: for row in cursor: fList.append(row) listGroup = listSplit(fList, outputNum) for x in listGroup: lyr.setSelectionSet("NEW", x) arcpy.CopyFeatures_management(lyr, arcpy.CreateUniqueName(outputFCName))
As @klewis mentioned you could use the Split By Attribute feature:
Esri provides the following sample code that you could use as mentioned:
# Name: SplitByAttributes.py # Description: Use the SplitByAttributes tool to split a feature class by # unique values. # Import required modules import arcpy #Set local variables in_feature_class = 'c:/data/base.gdb/ecology' target_workspace = 'c:/data/output.gdb' fields = ['REGION', 'ECO_CODE'] arcpy.SplitByAttributes_analysis(in_feature_class, target_workspace, fields)