6

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?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338

1 Answers1

7

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!)
    

enter image description here

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

enter image description here

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
  • I'm not sure. Give it a try. I have set seq as integer. – Kadir Şahbaz Dec 08 '20 at 00:06
  • Yes. I've tried something for duplicate values but I couldn't solve. – Kadir Şahbaz Dec 08 '20 at 00:09
  • I got that error. Make sure you typed the layer and field names in SearchCursor. – Kadir Şahbaz Dec 08 '20 at 00:20
  • 1
    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. – fatih_dur Dec 08 '20 at 00:32
  • I thought that. In your case, it would be fine. But it may return incorrect results for geographic coordinates. – Kadir Şahbaz Dec 08 '20 at 00:35
  • you could also export the attribute table to excel, do a sort and sequence fill there and join the result based on fid – Hans Erren Dec 08 '20 at 13:51