# Creating Unique IDs of points in order from west to east

I have a dataset with over 1000s points. I am wondering if I am able to give each point a unique ID starting from west to east.

I am using ArcMap 10.6. Is there a way to do this in ArcMap?

• Calculate new field xcoordinate > sort by xcoordinate > add new numeric field "seq" > fill field seq with counter see: gis.stackexchange.com/questions/193681/… Commented Dec 7, 2020 at 20:45
• A simple sort on easting and northing (descending) should work for this, though you might get more methodical results with large datasets if you use a grid to bin values first. See gis.stackexchange.com/questions/73978/… Commented Dec 7, 2020 at 21:45
• Commented Dec 7, 2020 at 22:30
• The solution in the link takes into account OID order, I guess. Commented Dec 7, 2020 at 23:46
• The Sort (management) gp tool will produce a sorted fc. You can set the sorting to be from left to right (cartesian). Then use the Create sequential number using Calc Field as stated above. Commented Dec 18, 2020 at 0:29

## 1 Answer

First, to be sure POINT_X has no duplicate values, run next two lines in Python console.

# change layer_name
x_values = [row[0] for row in arcpy.da.SearchCursor("layer_name", "POINT_X")]
len(x_values) == len(set(x_values)) # output should be True

If POINT_X has no duplicate values you can use the following script in Field Calculator.

• Open Field Calculator (by right click on seq field)

• Populate the parameters as in the image using the following script. (Don't forget to change layer_name in the script)

x_values = [row[0] for row in arcpy.da.SearchCursor("layer_name", "POINT_X")]
x_values.sort(reverse=True)

def add_unique_ids(x):
global x_values
i = x_values.index(x)
return i

• And call the method.

add_unique_ids(!POINT_X!)

The main limitation is that features with the same POINT_X get the same seq value. I couldn't figure it out yet.

• I'm not sure. Give it a try. I have set seq as integer. Commented Dec 8, 2020 at 0:06
• Yes. I've tried something for duplicate values but I couldn't solve. Commented Dec 8, 2020 at 0:09
• I got that error. Make sure you typed the layer and field names in SearchCursor. Commented Dec 8, 2020 at 0:20
• I think this is related to the data resolution, i.e., number of digits of X coordinate that you receive from ArcGIS and how they are saved in a python list. As a workaround, you can use round builtin function of python. In this answer, if you change row[0] to round(row[0], 4) and x_values.index(x) to x_values.index(round(x ,4)), you would be fine. Here, the value of 4 is arbitrary and presumed it will work in a projected CS. Commented Dec 8, 2020 at 0:32
• I thought that. In your case, it would be fine. But it may return incorrect results for geographic coordinates. Commented Dec 8, 2020 at 0:35