AnsweredAssumed Answered

How to calculate maximum value of different columns integrated in if else statement?

Question asked by GeoStudy on Jan 5, 2019
Latest reply on Jan 5, 2019 by GeoStudy

Hey guys,

hopefully you all started the new year well!

 

My problem is as follows (by the way I am new in programming with python in GIS):

There are 5 different slope-classes for my GIS analysis. The attribute table shows how many points per area belong to a certain slope-class (Example: Area 1: Slope 1 - 10 points, Slope 2 - 20 points, Slope 3 - 30 pints, Slope 4 - 10 points, Slope 5 - 0 points). In the table there are a hundred different areas, each row represents one area.

The goal is to determine a slope tendency for each area. The idea was to calculate the maximum of the different counted slope points for each area and then say that for example area 1 has a slope tendency of 3.

 

I tried to make an ifelse statement with integrated max function in the field calculator 

Pre-logic script code: 

def Ergebnis (!Join_Count_1!, !Join_Cou_2!, !Join_Cou_3!, !Join_Cou_4!, !Join_Cou_5):

if Join_Count_1 = max([!Join_Count_1!, !Join_Cou_2!, !Join_Cou_3!, !Join_Cou_4!, !Join_Cou_5!]):
return "1"

elif Join_Cou_2 = max([!Join_Count_1!, !Join_Cou_2!, !Join_Cou_3!, !Join_Cou_4!, !Join_Cou_5!]):
return "2"

elif Join_Cou_3 = max([!Join_Count_1!, !Join_Cou_2!, !Join_Cou_3!, !Join_Cou_4!, !Join_Cou_5!]):
return "3"

elif Join_Cou_4 = max([!Join_Count_1!, !Join_Cou_2!, !Join_Cou_3!, !Join_Cou_4!, !Join_Cou_5!]):
return "4"

elif Join_Cou_5 = max([!Join_Count_1!, !Join_Cou_2!, !Join_Cou_3!, !Join_Cou_4!, !Join_Cou_5!]):
return "5"

else
return "No Data"

 

Expression:

max([!Join_Count!, !Join_Cou_1!, !Join_Cou_2!, !Join_Cou_3!, !Join_Cou_4!])


When I am running the field calculator I always get a python syntax/parsing error. In a different version of this code I also got the indentation error in python.


Could somebody please help me and state where my errors are respectively show me where my way of thinking is wrong?? Maybe there are alternatives how to solve this problem????


Thank you very much in advance!!

Outcomes