I need to update the whole table with the new values in SI. However when I start a new cursor, the list of values seems to go away and I cannot update each row with its corresponding value.
How can I do this?
import arcpy
import math
path = 'C:\\ProgInGIS\\FinalExam\\Final\\Hydro.gdb'
sindex = 'SINDEX'
arcpy.env.workspace = path
input_fc = arcpy.GetParameterAsText(0)
input_test = 'streams_gcs'
fcs = arcpy.ListFeatureClasses()
spat_ref = arcpy.Describe(input_test).spatialReference
if spat_ref.type == 'Projected':
arcpy.AddMessage("{0} has {1} features. Using Planar calculations which differ from Geodesic".format(input_test, spat_ref.type))
if spat_ref.type == 'Geographic':
arcpy.AddMessage("{0} has {1} features. Using Geodesic calculations which differ from Planar".format(input_test, spat_ref.type))
field_names = arcpy.ListFields(input_test)
for field in field_names:
if field.name == sindex:
arcpy.DeleteField_management(input_test, sindex)
print('Deleted {0} field from {1}'.format(sindex, input_test))
arcpy.AddField_management(input_test, sindex, 'FLOAT')
with arcpy.da.SearchCursor(input_test, ['OID@', 'SHAPE@']) as cursor:
for row in cursor:
oid = row[0]
shape = row[1]
if shape.isMultipart is True:
arcpy.AddError('There are multipart features present and no calculations can be performed')
exit()
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))
si = round(channel / valley, 3)
s_index = {oid, si}
cursor2 = arcpy.da.UpdateCursor(input_test, [sindex])
for row2 in cursor2:
if row2[0] == 'None Type':
print('yes')
row2[0] = s_index[0]
cursor2.updateRow(row2)