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"?
asked Oct 31, 2018 at 7:45
-
1just 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 problemdru87– dru872018年10月31日 09:06:43 +00:00Commented Oct 31, 2018 at 9:06
1 Answer 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)
answered Oct 31, 2018 at 14:36
lang-py