Hi,
I have a SHP with these attributes:
ID1 | NAME1 | AREA | ID2 | NAME2 |
123 | John | 0,12 | 135 | Lisa |
123 | John | 1 | 246 | Veronica |
456 | Kyra | 3,2 | 246 | Veronica |
789 | Oliver | 4,5 | 123 | John |
012 | Nick | 78 | 123 | John |
012 | Nick | 8,9 | 100 | Nelson |
Then I need to make an expression based on ID´s - for example for JOHN.
"ID1=123 or ID2=123"
But then I need to export it as a new SHP but I want it with ID in output name.
So output file would be "Polygons_123"
For another file would be "Polygons_789" and so on....
Is there any option how to extract this value from expression and make it through Calculate value maybe? Or is there another way?
thank you.
Solved! Go to Solution.
Edit and run this code in the python window.
input_path = "path:/to/your/SHP.shp"
output_path = "path:/to/output/folder_or_gdb"
# get unique values for id1 and id2
raw_ids = [r for r in arcpy.da.SearchCursor(input_path, ["ID1", "ID2"])]
ids = [ri[0] for ri in raw_ids] + [ri[1] for ri in raw_ids]
unique_ids = list(set(ids))
# loop through unique_ids
for uid in unique_ids:
where_clause = "ID1 = {0} OR ID2 = {0}".format(uid)
output_name = "Polygons_{}".format(uid)
arcpy.conversion.FeatureClassToFeatureClass(input_path, output_path, output_name, where_clause)
don't know if it was ported back to arcmap, but
Split By Attributes (Analysis)—ArcGIS Pro | Documentation
then there may be the issue about output file names.
Edit and run this code in the python window.
input_path = "path:/to/your/SHP.shp"
output_path = "path:/to/output/folder_or_gdb"
# get unique values for id1 and id2
raw_ids = [r for r in arcpy.da.SearchCursor(input_path, ["ID1", "ID2"])]
ids = [ri[0] for ri in raw_ids] + [ri[1] for ri in raw_ids]
unique_ids = list(set(ids))
# loop through unique_ids
for uid in unique_ids:
where_clause = "ID1 = {0} OR ID2 = {0}".format(uid)
output_name = "Polygons_{}".format(uid)
arcpy.conversion.FeatureClassToFeatureClass(input_path, output_path, output_name, where_clause)