1

I've never used Python scripting before and can't seem to figure out how to use an If statement in the Field Calculator tool.

I have a field called 'MAX_GRIDCODE' which returns the highest force a piece of infrastructure is exposed to. I need to use this number to calculate a simple estimate of damage in the field 'DI'.

The statements I need are:

If "Max_GRIDCODE" >0 and <=0.5 then "DI" = 1
If "Max_GRIDCODE" >0.5 and <=1 then "DI" = 2
If "Max_GRIDCODE" >1 and <=1.5 then "DI" = 3
If "Max_GRIDCODE" >1.5 and <=2 then "DI" = 4
If "Max_GRIDCODE" >2 then "DI" = 5

How do I code this using ArcGIS 10.2 for Desktop?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 7, 2015 at 0:30

2 Answers 2

5

open CalculateField tool

for 'Field Name' parameter specify: DI

for 'Expression' parameter specify: x(!Max_GRIDCODE!)

for 'Code Block' parameter specify the code below

def x(v):
 if v > 2: return 5
 elif v > 1.5: return 4
 elif v > 1: return 3
 elif v > 0.5: return 2
 else: return 1
answered Jul 7, 2015 at 0:38
0
0

Esri Support provide an How To: Use IF statements in the Field Calculator:

Summary

The Field Calculator uses IF statements to calculate new values in the field of an attribute table. This article describes some common uses of IF statements in the Field Calculator and with Python scripts.

answered Nov 23, 2022 at 5:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.