4

I have a square grid feature class of 250 x 250 tiles. This will serve as a tile index for a a project. They currently have no identifying attributes other than a unique ID. I need to add a field to rename them by their row and column, e.g. "R001_C001" or something.

Is there a way to do this easily? I'm okay with python.

4
  • This would require a heavy programming (you need to figure out the relative position of each polygon). Would you consider using Grid Index Features or Create Fishnet GP tools? Mar 25, 2014 at 17:21
  • I generated the tiles with the Create Fishnet tool initially, and I got good tiles but no index. I tried Grid Index Features and the index that was returned was bad (every tiles was labeled -10) and I have no idea why.
    – Wes
    Mar 25, 2014 at 17:23
  • possible duplicate of ArcGIS Field Calculator Python numbering rows of fishnet
    – radouxju
    Mar 25, 2014 at 20:37
  • sorry, I had not seen the comment about the coordinate problem when I flagged as duplicate.
    – radouxju
    Mar 25, 2014 at 21:16

2 Answers 2

3

based on the fact that the tiles created by fishnet are ordered, here is a quick solution (without using the coordinates) and directly using a single line field calculator.

'C' + str((!OID!-1)/number_of_columns).rjust(3, '0') + '_R' + str((!OID!-1)%number_of_columns).rjust(3, '0') 

note : in my case, OID starts at 1 (gdb). In your case, number_of_columns is obviously 250.

1
  • Perfect! I had to switch the column and row letters around, but this worked for me. The final line was: 'R' + str(( !OID!-1)/250).rjust(3, '0') + '_C' + str(( !OID!-1)%250).rjust(3, '0'). Thanks a lot!
    – Wes
    Mar 26, 2014 at 11:33
3

Assuming that your grid is regular you can do this without any programming as a multi-stage attribute field calculation process.

  1. Create X and Y columns and populate them with the coordinates of the centroid of each polygon cell.
  2. Calculate the coordinate offset from the first column for X and first row for Y (remember that we're dealing with centroids here (i.e. not the actual origin of the grid), but you can get the coordinate by manually querying the appropriate cell's attributes. You can store this as another pair of fields, you just need to decide whether you want your rows and columns to start upper left or lower left and adjust the calculation of offset accordingly.
  3. Divide the offsets by your cell size (be careful of floating point issues (I'd probably convert to integer probably when I calculate the offsets). You could do this in one go with 2 and save adding too many fields.

And that's it! You now should have two fields one with your column number and one with your row number. You could create another field and concatenate the two fields as a string in the form you quote in your question but you can also use the two fields as an ID.

If you want, you can now delete the temporary fields you calculated as intermediary steps. This will save data bloat.

1
  • Thanks for the answer! This would work extremely well, but the area I'm looking at is huge. I actually tried this too, but the coordinates of the centroids drift too much and I'm running into the "flattening a round world" problem. The rows and columns tend to converge.
    – Wes
    Mar 25, 2014 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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