1

Creating unique identifier for cadastral parcels in ArcGIS 10.5 (ArcView)?

I'm adding selected parcels to a feature class and I would like to have a text prefix and then three or four digit number that increases as I add to the layer. The text prefix will be categorizing the type of parcel, the numbers will be for keeping a sequential count.

An old colleague gave me this script a few years ago, but no instruction.

Static recz As Long
Dim lStart As Long
Dim lInterval As Long
Dim IMap As String
Dim IMapID As String
'=================
'adjust start value and interval bellow
lStart = 500
lInterval = 1
IMap = "G505"

'=================
If (recz = 0) Then
  recz = lStart
End If
recz = recz + lInterval
IMapID = IMap & "." & recz
2
  • 1
    That's a VB script as I'm sure you're aware, ArcGIS is moving away from VB so I think it would be better to use the python parser. Are you after a tool or a field calculator expression? I'd think it would be better if this was implemented as a tool with two stages: 1 - find the existing highest number, 2 - calculate the parcels without an identifier from the next number in the series. This can be done with a python field calculator expression but would be incredibly slow and get slower as the dataset grows. Commented Jun 12, 2017 at 20:50
  • Thanks for the reply - we used it as a field calculator expression - adding 20 to 100 new parcels every few days. If I knew how to make a tool I would give it a try. Does anyone know an equivalent expression that would work in 10.5? I need to be able to set the prefix characters - and then add the sequential numbers. Thanks y'all!
    – Scott_B
    Commented Jun 12, 2017 at 22:39

1 Answer 1

1

As a straight translation into python field calculation:

gCurrentNum = 500    # Change this to the next available number
gInterval   = 1      # the step
gPrefix     = 'G505' # the prefix to the ID

def CalcID():
    # bring in the global variables
    global gCurrentNum
    global gInterval
    global gPrefix

    IMapID = '{}.{}'.format(gPrefix,gCurrentNum)
    gCurrentNum += gInterval # increment the current number by interval
    return IMapID            # return the unique identifier

But as I said it would be better as a tool trying to find the next starting number, this can be done in a field calculation but there are some dangers:

gCurrentNum = 0         # Change this to the next available number
gInterval   = 1         # the step
gPrefix     = 'G505'    # the prefix to the ID
gLayerName  = 'Parcels' # The name of the parcels layer
gFieldName  = 'ParcelID'# The field name containing the unique ID

# bypassing selection and definition queries read the
# feature class directly to make sure ALL rows are considered
Lay = arcpy.mapping.Layer(gLayerName)
with arcpy.da.SearchCursor(Lyr.dataSource,gFieldName) as SCur:
    for row in SCur:
        if not row[0] == None:              # if there is something in the field
            SplitString = row[0].split('.')   # break up the string at the dot
            if len(SplitString > 1):          # if it's in the expected format prefix.number
                if SplitString[1].isdigit():    # if the second element is a number
                    ThisNum = int(SplitString[1]) # make the 2nd element a numeric type
                    if ThisNum > gCurrentNum:     # if more than the current number
                        gCurrentNum = ThisNum       # make the current number equal to this (highest) number
gCurrentNum += gInterval                # increment the current number or the first will be equal to the highest

def CalcID():
    # bring in the global variables
    global gCurrentNum
    global gInterval
    global gPrefix

    IMapID = '{}.{}'.format(gPrefix,gCurrentNum)
    gCurrentNum += gInterval # increment the current number by interval
    return IMapID            # return the unique identifier

This goes into field calculator with a python parser but it is vital that the layer name and field name as stated in the expression is correct, I've set them to arbitrary values but you must change the layer and field to match your data.

Your Answer

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

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