[GIS] Writing If-Then Statement in ArcGIS Field Calculator using Python Parser

arcgis-10.0arcgis-desktopfield-calculatorif statementpython-parser

Scenario:

I have four fields: A, B, C and D

Field A is text-based and contains values from '000' up to some number 'xxx'
Field B contains a set of values (also text, but represented by numbers)
Field C contains a set of values (also text, but represented by numbers)
Field D is empty and waiting to be populated

I would like to construct an if-then statement in Field Calculator that does something like this:

If Field A = 000 then Field D = Field B, 
If Field A =/= 000 then Field D = Field C

I have spent the better part of my day trying to find the proper 'language' to ask Field Calculator, but I'm stuck. I have 0 programming experience also.

Could anybody show me how this should be set up either in Python?

I'm using ArcGIS 10.0.

Best Answer

Using Python, the calculation would look like this:

For the Pre-Logic Script:

def Calc(a,b,c):
 if a == "000":
      return b
 else:
      return c

For the expression:

Calc( !A! , !B! , !C! )