Select to view content in your preferred language

Evaluating two fields and assigning value in a third?

814
2
01-27-2012 09:23 AM
SaraJK
by
Frequent Contributor
I think I've reached a point where I need a Python script but I'm not sure exactly how to proceed. This is what I would like to do:

If the value in Field1 is between 100 and 200
and the value in Field2 is 11,
then Field3 is calculated to "red"

and so on.

I've found a few code examples but I'm not sure where to execute - can I do this in the field calculator? the raster calculator? or do I need a stand alone script?

Once I figure this out, then I will try to tackle the code!

Thanks for any pointers.
Tags (2)
0 Kudos
2 Replies
JeremyLuymes
Regular Contributor
I would use an upate cursor. Something like this might work

cur = gp.UpdateCursor(insertnameoffeatureclass)
row = cur.Next()
while row:
    if row.Field1 >= 100 and row.Field1 <= 200 and row.Field2 == 11:
        row.Field3 = "red"
    cur.UpdateRow(row)
    row = cur.Next()
del cur, row
0 Kudos
markdenil
Frequent Contributor
The Update cursor is a good way to do it, but
some pre-logic code in the field calculator would work too.

if ([Field1] >= 100 and [Field1] <= 200) and [Field2] = 11 then
    theValue = "red"
else
    theValue = [Field3]
end if


[Field3] = theValue
0 Kudos