Oct-04-2019, 06:57 PM
I have 4 columns(ID_TRC, LENGTH, Categorie, Score) my code is supposed to iterate through the attribute table and for each value of ID_TRC, if the value if unique, assign New_Score = Score, and if the value is repeating, comparing its corresponding values for LENGTH and Categorie as in the code below for each record of ID_TRC.
finally, a new table is to be created with just ID_TRC and New_Score(I written the code for this part yet.)
finally, a new table is to be created with just ID_TRC and New_Score(I written the code for this part yet.)
from tkinter import * import arcpy field_name = "Norm Score" field_type = "FLOAT" fc = "C:/Users/umroot/Desktop/tersoo/GIS_data/GUI_CODES/output/LandUse_Roads.shp" field = ['ID_TRC','LENGTH', 'Categorie', 'Score'] with arcpy.da.UpdateCursor(fc, field) as cursor: for row in cursor: ID_TRC = row[0] LENGTH = row[1] Categorie = row[2] Score = row[3] ScoreSum = 0.0 LengthSum = 0.0 New_score= 0.0 #rowCur = row #rowPost = cursor.next() with arcpy.da.SearchCursor(fc, field) as incursor: for rows in incursor: if ID_TRC == rows[0] and LENGTH != rows[2] and Categorie != rows[1]: ScoreSum += Score*LENGTH LengthSum += LENGTH New_score = float(ScoreSum/LengthSum) print("same ID but different lengths and Category",ID_TRC,New_score) elif ID_TRC == rows[0] and LENGTH == row[2] and Categorie != rows[1] : ScoreSum += Score*LENGTH New_score = float(ScoreSum/LENGTH) print("same ID but equal length different category",ID_TRC, New_score) elif ID_TRC == rows[0] and LENGTH != row[2] and Categorie == rows[1] : ScoreSum += Score*LENGTH New_score = float(ScoreSum/LENGTH) print("same ID but equal length different category",ID_TRC, New_score) elif ID_TRC != rows[0]: New_score = Score print("Different ID",ID_TRC, New_score) cursor.updateRow(row)Please help,....thanks