Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

How to iterate through unique values in a field name

$
0
0
I have a street atlas of our county in data driven pages (632 pages). I want to divide these up into mini atlases based on the fire district, so that I can give each fire department a mapbook of only the pages in their district.

Essentially what I envision the process to look like is to:

1. iterate or loop through all the unique values in the NAME field within my FireBoundaries FC.
2. do a select by location for each unique value: Grid Pages that intersect with the selected FireBoundary.
3. Export the selected pages to pdfs in a folder that is the same name as the FireBoundary.

So in the end I would have a folder for each district.

I started this process in model builder and then realized it is not quite possible, so I'm trying to switch to python to automate. In my head it seems really simple but I'm just not getting anywhere. So far I have created a unique list of values, but I'm not sure if that is the starting point or if my process is correct:

Code:

import arcpy

FireBoundary = r"Path/to/my/sdeconnection"
field = "NAME"

# Use SearchCursor with list comprehension to return a unique set of values in the specified field
values = [row[0] for row in arcpy.da.SearchCursor(FireBoundary, (field))]
uniqueValues = set(values)
print(uniqueValues)

Any pointers or tips would be appreciated.

Viewing all articles
Browse latest Browse all 2485

Trending Articles