Created
July 14, 2015 18:51
-
-
Save cindygis/d4ee18f3030209fd49e0 to your computer and use it in GitHub Desktop.
Populates the next highest numbers for a feature class based on the previous max
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arcpy | |
lyr = arcpy.management.MakeFeatureLayer(r"C:\Some\Arb\Folder\work.gdb\ftr_wrp_Pipe") | |
field = "GIS_ID" | |
def getWhereQry(exp): | |
return """ "{0}" IS {1} """.format(field, exp) | |
# Gets the previous highest GIS ID value. Set n = 0 for new feature class | |
n = max(int(row[0].split("-")[1]) for row in arcpy.da.SearchCursor(lyr, field, where_clause=getWhereQry("NOT NULL"))) | |
numstring = "00000" | |
prefix = "WRP" | |
sep = "-" | |
# Populate blank GIS IDs with new values | |
with arcpy.da.UpdateCursor(lyr, field, where_clause=getWhereQry("NULL")) as cursor: | |
for row in cursor: | |
n += 1 | |
numstring_length = len(numstring) - len(str(n)) | |
row[0] = prefix + sep + numstring[:numstring_length] + str(n) | |
cursor.updateRow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment