I should probably start a new question, by thought I would check here first. This code will run all the way through, all the fields gat added but the one at line 139 with the code block does nothing and I dont get any errors. I have tried changing the " to ' changing all the quotes and do not see any changes.
am I doing the codeblock wrong?
'''---------------------------------------------------------------------------
'''
import arcpy as arcpy, datetime
import os
arcpy.env.overwriteOutput = True
arcpy.env.workspace = 'in_memory'
startTime = datetime.datetime.now()
arcpy.AddMessage ('Start processing at :')
arcpy.AddMessage (startTime.strftime('%Y-%m-%d %H:%M'))
workspace = arcpy.GetParameterAsText(0)
windP = arcpy.GetParameterAsText(1)
windS = arcpy.GetParameterAsText(2)
aprx = arcpy.mp.ArcGISProject('CURRENT')
m = aprx.activeMap
lyrs = m.listLayers()
for lyr in lyrs:
if lyr.getSelectionSet():
sel_lyr = lyr.dataSource
field = 'GNIS_Name'
rows = arcpy.da.SearchCursor(lyr,field)
for row in rows:
Stream_Pre = row[0]
Stream_Name = Stream_Pre.replace(' ','_')
stream = os.path.join(str(workspace),Stream_Name)
arcpy.cartography.SimplifyLine(sel_lyr, stream, 'POINT_REMOVE', '45 Meters',
'RESOLVE_ERRORS', 'NO_KEEP', 'CHECK', '')
arcpy.management.SplitLine(stream,stream + '_Split')
arcpy.Buffer_analysis(stream + '_Split' , stream + '_Buff', '63 Feet', 'RIGHT'
, 'FLAT', 'NONE', '', 'PLANAR')
arcpy.AddField_management(stream + '_Buff', 'Angle', 'LONG', '', '', '', '',
'NULLABLE', 'NON_REQUIRED', '')
arcpy.CalculatePolygonMainAngle_cartography(stream + '_Buff', 'Angle',
'GEOGRAPHIC')
arcpy.AddField_management(stream + '_Buff', 'wind', 'LONG', '', '', '20', '',
'NULLABLE', 'REQUIRED', '')
arcpy.CalculateField_management(stream + '_Buff', 'wind', windP)
expression1 = 'getClass((!Angle!)+ !wind!)'
codeblock1 = '''
def getClass(n):
if n < 0:
return n * -1
else:
return n'''
arcpy.CalculateField_management(stream + '_Buff', 'wind', expression1,
'PYTHON3', codeblock1)
arcpy.AddField_management(stream + '_Buff', 'wind2', 'LONG', '', '', '20', '',
'NULLABLE', 'NON_REQUIRED', '')
arcpy.CalculateField_management(stream + '_Buff', 'wind2', windS)
expression2 = 'getClass((!Angle!)+ !wind2!)'
arcpy.CalculateField_management(stream + '_Buff', 'wind2', expression2,
'PYTHON3', codeblock1)
arcpy.AddField_management(stream + '_Buff', 'Index', 'LONG', '', '', '20', '',
'NULLABLE', 'REQUIRED', '')
expressionReclass = "Reclass(!wind!)"
codeblock_wind ='''def Reclass(wind):
if (wind >= 0 and wind <= 20):
return 5
elif (wind > 20 and wind <= 70):
return 4
elif (wind > 70 and wind <= 110):
return 3
elif (wind > 110 and wind <=160):
return 2
elif(wind > 160 and wind <=200):
return 1
elif(wind > 200 and wind <=250):
return 2
elif(wind > 250 and wind <=290):
return 3
elif(wind > 290 and wind <=340):
return 4
elif(wind > 340):
return 5'''
arcpy.CalculateField_management(stream + '_Buff', 'Index', expressionReclass,
'PYTHON_9.3', codeblock_wind)
arcpy.AddField_management(stream + '_Buff', 'Index2', 'LONG', '', '', '20', '',
'NULLABLE', 'NON_REQUIRED', '')
expressionReclass2 = 'Reclass(!wind2!)'
codeblock_wind2 = '''def Reclass(wind2):
if (wind2 >= 0 and wind2 <= 20):
return 5
elif (wind2 > 20 and wind2 <= 70):
return 4
elif (wind2 > 70 and wind2 <= 110):
return 3
elif (wind2 > 110 and wind2 <=160):
return 2
elif(wind2 > 160 and wind2 <=200):
return 1
elif(wind2 > 200 and wind2 <=250):
return 2
elif(wind2 > 250 and wind2 <=290):
return 3
elif(wind2 > 290 and wind2 <=340):
return 4
elif(wind2 > 340):
return 5'''
arcpy.CalculateField_management(stream + '_Buff', 'Index', expressionReclass2,
'PYTHON_9.3', codeblock_wind2)
arcpy.AddField_management(stream + '_Buff', 'SumOfRanks', 'SHORT', '', '',
'20', '', 'NULLABLE', 'NON_REQUIRED', '')
arcpy.CalculateField_management(stream + '_Buff', 'Index', '!Index!+ !Index2!',
'PYTHON_9.3', '')
arcpy.AddField_management(stream + '_Buff', 'Class', 'SHORT', '', '', '20', '',
'NULLABLE', 'NON_REQUIRED', '')
codeblock3 = '''
def Reclass(SumOfRanks):
if (SumOfRanks >= 0 and SumOfRanks <= 1):
return 1
elif (SumOfRanks > 1 and SumOfRanks <= 4):
return 2
elif (SumOfRanks > 4 and SumOfRanks <= 6):
return 3
elif (SumOfRanks > 6 and SumOfRanks <= 8):
return 4
elif (SumOfRanks > 8 and SumOfRanks <= 10):
return 5'''
arcpy.CalculateField_management(stream + '_Buff', 'Index',
'Reclass(!SumOfRanks!)', 'PYTHON_9.3'
,codeblock3)
m.addDataFromPath (stream + '_Buff')
endTime = datetime.datetime.now()
arcpy.AddMessage ('Finished processing at :')
arcpy.AddMessage (endTime.strftime('%Y-%m-%d %H:%M'))
arcpy.AddMessage ('Process duration:')
arcpy.AddMessage (endTime - startTime)