# How to add an ID based on attributes in ArcMap 10.1

Given are:

• a polygon shapefile/feature class (FC) containing municipal districts
• a point shapefile/FC containing locations of, lets say, trees.

My goal is to append an unique value (1, 2, 3, ...) to the point shapefile/FC which is:

1. sorted from north to south (or vice versa)
2. and sorted/grouped by the municipal districts (the priority of sorting lies on the municipal districts)

I managed to solve 1. by generating y-coordinates for each point and than running this script which calculates and sorts unique values by means of the the y-coordinate column:

However, I do not know how to solve 2. Finally my map should look like this (the numbers in red are the ones I'd like to calculate instead):

• I would strongly suggest rethinking your design. A unique ID should not have any semantic meaning (like its ordering meaning something). Its sole purpose is to uniquely identify a record. If you want to relate the points to the polygons using IDs, create an explicit foreign key. This can be easily accomplish with a spatial join. Commented Apr 17, 2014 at 8:51
• Thank you! The unique ID is not touched at all. Beside the shapfile's/FC's unique ID I'd like to have a further column with a numbering sorted in ascending order only for visualizing purposes. I also thought of a spatial join but this will lead to the same value for all points within the same polygon. And I'd like to have unique ones... Commented Apr 17, 2014 at 9:15
• What about unique values with a spatial join to polygons but different number range? Like in your example, the upper polygon would have 100 as number. Join to your points and you'll get 101 and 102. Then points in the next polygon gets 201, 202 etc. Commented Apr 17, 2014 at 9:24
• There are some ideas and SQL-based solutions in this question for a related but not identical problem: How to number polygons according to their spatial relationships? Commented Apr 17, 2014 at 9:27
• @Martin Thanks for your straight forward solution. Running the script mentioned in the question again will lead to my aspired goal. If you like, just write an answer with this hint and I'll mark it as answered. Commented Apr 17, 2014 at 9:33