Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

The codeblock below is run on Field1 and calculates Field1 to equal Field2 if they are not equal. Else it returns Field1. My question is, does the else statement actually recalculate Field1 to equal itself or does it leave Field1 as is. Basically if Field1 is equal to Field2, I don't want Field1 to recalculate to itself.

def update(Field1,Field2):
  if Field1 != Field2:
    return Field2
    return Field1
share|improve this question
What's there to "recalculate"? It's just placing whatever value is in field1 back into field1. I don't understand the concern. If you leave out the else statement, it will Null out the values that don't fit the if statement. –  ian Apr 9 at 19:09
I think there is some confusion in what you are asking. Stated another way, you want to know whether the else statement DOES something and if so how can you make it do nothing - ie if different change value else do nothing. This raises the question as bcollins asks, why not just calc F1 to F2, unless you're trying to save some processing time/power because of an extremely large dataset (which would be way over my head in terms of effectiveness and practicality). –  Chris W Apr 9 at 19:19
I guess I didnt' word my question in the best way but what Chris mentioned is exactly what I was getting at. My calculations are taking an extremely long time due to the number of records and so I was just curious if the "else" statement was also "processing". –  Steve Apr 9 at 20:43
@Steve are you running the calc outside an edit session? Also, running a script outside ArcMap would probably be your best bet - speed wise. –  ian Apr 10 at 3:02
@Steve With that additional information I quickly located a thread on the ESRI forum that may give you some direction on continuing to troubleshoot - it seems you are not the first person to run into this. forums.arcgis.com/threads/…!!! There were also some other related results by Googling 'field calculate SDE'. –  Chris W Apr 11 at 3:35
show 3 more comments

4 Answers 4

up vote 2 down vote accepted

The return value will only ever be set to the field you are calculating. Any fields you use to compute that value are not changed.

In the example below, only SHORT_NAME field would be changed.

This will also set every record in the field whether or not the value is the same.

  • So I guess more to your question, if you are setting the values for field1 and your function returns field1 value, you will be simply be calculating the new value to old value.

  • Maybe your function is just to show a trival example, but it seems it could just be shorten to setting field1 directly to field2.

enter image description here

share|improve this answer
add comment

The answer is yes, the way that is written an operation is being performed on every record. I haven't gotten into python yet, so I don't know if there is a 'do nothing' option - as Ian pointed out, without the else it will null the values. I see two possible solutions that are sort of the same if there is no 'do nothing' option. One, you would have to check for equivalence first, outside of the field calculation command instead of within it. Similarly, field calculate can be run on just selected records so you could select all records where they aren't equal and then calc F1 to F2 on only that set. Per my comment, I don't know what the actual impacts on processing time are and if they would be significant between just updating everything and trying to only modify what actually needs to be changed.

share|improve this answer
Your suggestion of doing the calculate on selected records seems to be working best for me so far. Thanks for the suggestion :) –  Steve Apr 25 at 19:00
add comment

As far as I know the field calculator only updates the field you want to calculate (usually you start the field calculator with the right mouse click on the field you want to recalculate and that is where the return value leads to). Same when you start the field calculator by using the arcpy expression calculateField_management.

share|improve this answer
add comment

I think the answer to your question is yes. Your code says to return Field1 if Field1 is equal to Field2, so it is reassigning those same values to Field1. This shouldn't be a problem though, I would not think.

I agree with ian in that you could just leave out the else statement, and then it wouldn't be reassigning.

I also assume you actually put in the bottom window of the Field Calculator (below the codeblock) where it would say "Field1 = "

update( !Field1!, !Field2!)
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.