Greetings. I am working on a project trying to get sequential Plan ID numbers for polygons produced in different year and different counties. I am using the field "County" to derive my County ID number (it is a string) and a "Year" field to derive my year value (alos a string. The format I am looking for is:
2012-401-1
2012-401-2
2012-401-3
2012-363-1
2012-363-2
2011-401-1
2011-401-2
Any help that y'all could provide would be greatly appreciated.
import arcpy myFC = r"C:\temp\test.shp" yearField = "YEAR" countyField = "COUNTY_CD" sequenceField = "SEQUENCE" #Integer concatField = "CONCAT" #text of sufficient length trackingDict = {} updateRows = arcpy.UpdateCursor(myFC) for updateRow in updateRows: yearValue = updateRow.getValue(yearField) countyValue = updateRow.getValue(countyField) if (yearValue, countyValue) in trackingDict: trackingDict[(yearValue, countyValue)] = trackingDict[(yearValue, countyValue)] + 1 else: trackingDict[(yearValue, countyValue)] = 1 sequenceId = trackingDict[(yearValue, countyValue)] updateRow.setValue(sequenceField, sequenceId) updateRow.setValue(concatField, str(yearValue) + "-" + str(countyValue) + "-" + str(sequenceId)) updateRows.updateRow(updateRow) del updateRow, updateRows
How about something like this:
***untested code***import arcpy myFC = r"C:\temp\test.shp" yearField = "YEAR" countyField = "COUNTY_CD" sequenceField = "SEQUENCE" #Integer concatField = "CONCAT" #text of sufficient length trackingDict = {} updateRows = arcpy.UpdateCursor(myFC) for updateRow in updateRows: yearValue = updateRow.getValue(yearField) countyValue = updateRow.getValue(countyField) if (yearValue, countyValue) in trackingDict: trackingDict[(yearValue, countyValue)] = trackingDict[(yearValue, countyValue)] + 1 else: trackingDict[(yearValue, countyValue)] = 1 sequenceId = trackingDict[(yearValue, countyValue)] updateRow.setValue(sequenceField, sequenceId) updateRow.setValue(concatField, str(yearValue) + "-" + str(countyValue) + "-" + str(sequenceId)) updateRows.updateRow(updateRow) del updateRow, updateRows