0

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"?

dru87
1,4779 silver badges23 bronze badges
asked Oct 31, 2018 at 7:45
1
  • 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 Commented Oct 31, 2018 at 9:06

1 Answer 1

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

answered Oct 31, 2018 at 14:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.