TransWikia.com

Calculating Sequential Field ID For Unique Identifier using Field Calculator

Geographic Information Systems Asked by hoorayforcontours on March 7, 2021

I have a feature class of 7308 features. I have given each feature a unique name (WM-0001 for example) as the FID’s jump all over the place. I realized that my new ID’s do not match up with the number of features in my table – turns out that I missed a number in renaming them and have to replace about 4000 feature ID’s now. Rather than doing it all manually is there a script I can create in Field Calculator to rename all the features with the same ID – 1 number so that the numbers follow the proper naming convention?

Example: my features go WM-1000, WM-1001, WM-1002, WM-1003, WM-1005, WM-1006, WM-1007 …, WM-7308, WM-7309

One Answer

It is not necessary to give each feature unique value through FID, sometimes when a feature is deleted the FID of the feature got skipped, you can use this function in your Python's Pre-logic Script Code of field calculator:

rec=0
def autoIncrement():
 global rec
 pStart = 1 #adjust start value, if req'd 
 pInterval = 1 #adjust interval value, if req'd
 if (rec == 0): 
  rec = pStart 
 else: 
  rec = rec + pInterval 
 return "Text" + str(rec) #change the "Text" as required

and in below text:

autoIncrement()

Answered by Saad Asif on March 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP