2

I have an areal feature class that has approximately 4,700 features. I need to divide this feature class into multiple feature classes that contain EXACTLY 60 features in each. Location of features have no matter. Yes, that will create nearly 80 feature classes with SplitByAttributes, that is what I need.

There are no attributes to sort with. Grouping Analysis can force creation of 80 groups with attributes, but creates too many features in some files, it is not uniform and not able to force the number of features (that I have knowledge of).

Anyone have any idea how to export a specific number of features to new feature classes?

1

You can add a temporary Field, integer type. Calculate it with int(!Objectid! / 80)
Use this temp field for SplitByAttribute. File Geodatabase, Objectid, normally starts at 1 while Shapefile, Fid, normally starts at 0. The last group may not be exactly 80, unless the entire count is a multiple of 80.

| improve this answer | |
0

If you have an object ID, you could use a simple python script to loop through the feature class to feature class tool and select object ids in increments of 80 as your "where_clause".

| improve this answer | |
  • 1
    +1. Read all OID into list > break into sublists of length 60 > build SQL query from values > export. – Paul Jan 11 '17 at 21:45
0

You can use a script in the python window to achieve this. I did a quick test with a 96 feature dataset which I split into shapefiles of 8 features each.

If you enter the following into the python window (minus the notes after the #), making changes for variables such as the number of features per featureclass, layer name, output path etc., you should have success.

import math

outputBaseFile = r"C:\OUTPUTPATH\NEWFILENAME_"
reqNum = 8   #features per featureclass

totalFeatures = float((arcpy.GetCount_management("YOUR_LAYER")).getOutput(0))   #this counts the number of features in your data
maxReps = ceil(totalFeatures / reqNum)  #this determines the number of new feature classes

count = 1
startNum = 1

while count <= maxReps:
    sqlQuery = '"OBJECTID" >= ' + str(startNum) + ' AND "OBJECTID" <= ' + str(reqNum * count) 
    arcpy.SelectLayerByAttribute_management("YOUR_LAYER","NEW_SELECTION", sqlQuery)
    outputFile = outputFileBase + str(startNum) + "_to_" + str(reqNum * count) + ".shp"
    arcpy.CopyFeatures_management("YOUR_LAYER",outputFile)
    count += 1
    startNum += reqNum

Note that in this code I just named the files with the ranges each would contain, and even though my last file only had seven features, it was still named with an 8 number range. This was just to save time writing, and you could implement your own solution to apply the correct range to the final file. Of course, you could use a totally different method for identifying your output files.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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