Why does the field populate with the same number, but prints correclty?
import arcpy
import rivers
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"C:\Data"
import math
def sinuosity(shape):
channel = shape.length
deltaX = shape.firstPoint.X -shape.lastPoint.X
deltaY = shape.firstPoint.Y -shape.lastPoint.Y
valley = math.sqrt(pow(deltaX, 2) + pow(deltaY, 2))
return channel/valley
fc = "streams.shp"
new_field = "Sindex"
with arcpy.da.SearchCursor(fc, ["OID@", "SHAPE@"]) as cursor:
for row in cursor:
oid = row[0]
shape =row[1]
si = rivers.sinuosity(shape)
print (f"Stream ID {oid} has an sinuosity index of {si:.3f}")
arcpy.AddField_management (fc, new_field, "DOUBLE" )
arcpy.CalculateField_management(fc,new_field, si)