I am using SplitLayerByAttributes toolbox. It’s a very useful tool for me to process certain activities. As you know, I can split the feature class as per 1 field. What if I want to split the features by 2 fields. In the below mentioned example: Here I would like to split the feature based on 2 fields. i.e “parcel_type” and “priority_takes” Main field is “parcel_type” Secondary field is “priority_takes” = Corridor

Right now I have run the toolbox twice with 2 different field and you can see the results over here. If at all possible, Splitting a feature with 2 fields then the corridors will be the subdivision in the “Parcel_types” features. Please let me know if you have any solution or any other toolbox available in arcscripts website.

enter image description here

enter image description here

enter image description here


You can try the below script just change the parameters- paths names etc.

import arcpy,os
arcpy.env.overwriteOutput = 1

###Change Below

input = r'C:\Users\\Documents\ArcGIS\Default.gdb\AdminBndL'
First_Field ='F_Type'
First_Field_Value = 'Divisional Boundary'
Second_Field = 'RefNamL'
Output = r'C:\Users\Documents\ArcGIS\Default.gdb'
Prefix = '_test'

###Change Above

input = arcpy.MakeFeatureLayer_management(input)
arcpy.SelectLayerByAttribute_management(in_layer_or_view=input, selection_type="NEW_SELECTION", where_clause="{0} = '{1}'".format(First_Field,First_Field_Value))
def unique_values(table, field):
    with arcpy.da.SearchCursor(table, [field]) as cursor:
        return sorted({row[0] for row in cursor})
flds = unique_values("sel",Second_Field)

for i in flds:
    sql = "{0} = '{1}'".format(Second_Field,i)
    name = (i+Prefix).replace("  ","").replace(" ","")

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.