I have a layer in which the order of the OBJECTID's is rather random.

How do I assign a new field in the data table that assign's number to each polygon based on it's position on the map?

I'd like to have the top left polygon have number 1 and then increment from left to right, top to bottom.

1 Answer 1


You can use Sort tool as follows:

Sort>> input your layer>> Field=Shape >> Spatial Sort Method = UL (Upper Left)

Result: new layer file with sorted features depending on spatial location.

Then; to add new sorted id in your new sorted shapefile>> add new filed (name e.g: id) >> calculate field >> python>> show code block

//add to the box above
def autoIncrement(): 
 global rec 
 pStart = 1  
 pInterval = 1 
 if (rec == 0):  
  rec = pStart  
  rec += pInterval  
 return rec

 //add this line in the small box below
  • This is a good solution but @Luuklag needs to consider if they actually want their original data sorted spatially as there may be some underlying trend that will get blitzed. Without them actually explaining anything about their data I'm guessing it is some sort of census related question, if so maybe worth their while exploring at this Q&A?
    – Hornbydd
    Feb 15, 2018 at 17:09
  • @Hornybydd Yeah maybe that could happen, but it always depends on the data and the requirements
    – Moh
    Feb 15, 2018 at 17:12
  • Output of sort will have ordered object id or fid, no need field calculator.
    – FelixIP
    Feb 15, 2018 at 19:34
  • Thanks for your answer. @Hornbydd: It is indeed some sort of census data, however the FID's contain no real information of use. The order they are assigned in is unknown to me, and not relevant. I want to order them to make it easier to assign values to them, as it makes numbers easier to find on a printed version.
    – Luuklag
    Feb 16, 2018 at 7:57
  • @User2009, for me your code just copies the FID's not the order in which they are sorted right now...
    – Luuklag
    Feb 16, 2018 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.