Sunday, 14 July 2019

python - Add row and column name to square grid feature in ArcGIS


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.



Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...