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?
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?
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.
SearchCursor.
– Kadir Şahbaz
Dec 08 '20 at 00:20
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.
– fatih_dur
Dec 08 '20 at 00:32
OIDorder, I guess. – Kadir Şahbaz Dec 07 '20 at 23:46Sort (management)gp tool will produce a sorted fc. You can set the sorting to be from left to right (cartesian). Then use theCreate sequential number using Calc Fieldas stated above. – gotchula Dec 18 '20 at 00:29