Select to view content in your preferred language

Batch Export of rows in attribute Table

592
3
01-20-2023 07:10 AM
Labels (2)
TimothyODoherty
New Contributor II

Hi,

 

I am working in ModelBuilder and having trouble exporting the data into individual features.

I have an attribute table with >500,000 polyliones, I have the grouped the polylines into ~250 groups and want to export each group as their own feature. My plan was to use the 'select layer by attribute' tool but how would I batch run this to export all features in one simple tool? 

0 Kudos
3 Replies
RhettZufelt
MVP Notable Contributor

Sounds like the Split by Attributes tool.

R_

0 Kudos
TimothyODoherty
New Contributor II

Yes, I understand that Rhett. But what I am struggling with would be how to I run a 'Select by Attribute Tool' for each unique value in my field? 

0 Kudos
RhettZufelt
MVP Notable Contributor

I don't mess with models much, but suspect an interator would work here.

I'd use python and:

create an empty list

use search cursor to populate the list with all the values of the field

turn that list into a set (so is uniuqe without duplicates)

iterate through the list and pass that to the Select By Attributes

export.

fc = r'Database Connections\pathtofeatureclass'
search_field = 'AttField'
AttList = []
with arcpy.da.SearchCursor(fc, [search_field]) as cursor:
    for row in cursor:
       AttList.append(row[0])

AttSet = set(AttList)

for att in AttSet:
    where = f"{search_field} = '{att}'"
    arcpy.management.SelectLayerByAttribute(fc, "NEW_SELECTION", where)
    ## Export or other stuff

Should work if running in Pro with fc loaded.  If not, will probably have to make feature layer first as the SelectByAttributes needs a view/layer not a feature class.  If so, could skip the SelectByAttributes and just pass the same where clause to the MakeFeatureLayer GP tool, then export the feature layer.

R_

0 Kudos