Field Calculation: trying to define a value with the information of 2 columns

327
1
Jump to solution
10-26-2022 10:28 AM
Labels (3)
JaniceHau
New Contributor

Hi, I was trying to calculate a value using the information of 2 columns, I know that it needs to implement a python elif and function. But I don't know how to make it works. Here is my code:

JaniceHau_0-1666805271677.png

 

Code block:
def Resistance(x, y):
if x == "water":
return 100
elif x == "barrier":
return 100
elif x == "linear_feature" and y == "corridor" or y == "raceway" or y == "elevator":
return 100
elif x == "linear_feature" and y == "footway" or y == "bridleway" or y == "track" or y =="path", or y == "proposed" or y == "abandoned" or y == "rest area":
return 20
elif x == "linear_feature" and y == "motorway" or y == "motorway_link" or y == "trunk" or y == "trunk_link" or y == "escape" or y == "construction" or y == "turning loop":
return 70
elif x == "linear_feature" and y == "primary" or y == "secondary" or y == "tertiary" or y == "primary_link" or y =="secondary_link" or y == "tertiary_link" or y == "unclassified" or y == "road":
return 50
elif x == "linear_feature" and y == "residential" or y == "cycleway" or y == "living street" or y == "platform" or y =="bustop"
return 30
elif x == "linear_feature" and y == "services" or y == "pedestrain" or y == "crossing" or y == "steps"
return 20
elif x == "residential":
return 40
elif x == "institutional":
return 30
elif x == "open_green_area":
return 30
elif x == "hetero_green_area":
return 30
elif x == "dense_green_area":
return 20
elif x == "resourceful_green_area":
return 10
elif x == "building":
return 100
else:
return 0

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

The syntax is:

Resistance(!feature!, !type!)

View solution in original post

1 Reply
JoshuaBixby
MVP Esteemed Contributor

The syntax is:

Resistance(!feature!, !type!)