1

I would like to create sequential numbers in a field of a point shapefile that start from 0 with an interval of 0.050. The main code works whenever the start number is not zero.

The original code to put in the codeblock from (https://support.esri.com/en/technical-article/000011137) looks like this:

rec=0 
def autoIncrement(): 
   global rec 
   pStart = 1 
   pInterval = 1 
   if (rec == 0): 
      rec = pStart 
   else: 
      rec += pInterval 
   return rec

How I can make it in arcpy with a “codeblock” and “Expression”?

  • 1
    just change rec=0 to something like rec=-999, set pStart=0 and pInterval=0.05 and then update 'if (rec == -999):' this should solve your problem – dru87 Oct 31 '18 at 9:06
1

You can write a function which yields incrementing values:

import arcpy
fc = r"Buildings" #Change
seqfield = "SeqField" #Change

def frange(start, end, step):
    tmp = start
    while(tmp < end):
        yield tmp
        tmp += step

seq = frange(0,100000,0.5)

with arcpy.da.UpdateCursor(fc, seqfield) as cursor:
    for row in cursor:
        row[0] = next(seq)
        cursor.updateRow(row)

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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