1

I have a model in model builder where I add 2 fields, "field 1" and "field 2". For each field I calculate their values using the calculate field tools. Afterwards I add a third called "Field 3" of which the calculation is based on the calculations done in field 1 and field 2.

My questions is if it possible to add the third field directly from my feature class without first calculating field 1 and field 2. If I would calculate field 3 as shown in my picture below, I cannot refer to field 1 and field 2; not even if I use preconditions (without first running the first part of the model until adding field 3).

Calculate field 3 based on field 1 and 2 without making them direct dependent

I realize that this would be possible if I add field 1, calculate field 1, add field 2, calculate field 2, add field 3, and then calculate field 3. In this case 'field 1'and 'field 2' will be shown in my field 3 calculation tool. The problem is that the model visually becomes a very long model that lacks overview (as I need need to do this for more fields before I calculate the last field).

Is there a way in ArcGIS Model Builder to calculate a field based on two other fields without that field 3 is directly linked to the two fields?

  • I am confused. Do you want to forgo creating and calculating field one and two altogether? Because your bold sentence makes it seem like that is your goal. If so, then yes, you can do what you asked. However, it appears that you have field 1 and 2 as preconditions - so that doesn't seem to be the goal of your model. So, I am not really sure what you are trying to do. – Barrett Mar 9 '15 at 21:27
  • It would be possible if you first calculate field1, then field 2 and then add and calculate field3. It is not ppossible, however, to add and calculate field3 that is not directly linked to the field1 and field2 calculations. In my model I used precoonditions to show that field1 and field 2 need to be calculated first but that I already want field3 to be added in the meantime. In the end I used ppython scripts instead of model builder to solve my issue. – Jelle May 25 '15 at 16:24
3

Would you consider a Python solution, especially if you have to do a lot of separate calculations in your model? The problem with the field calculator for a script process is that it is slow and not expanding your thinking beyond a manual process. Why process every row in your table every time you do a field calculation when a cursor can process all of your calculations as it processes every row one time.

With a Python approach you would add all of your fields first without calculating them, then process an update cursor which can simultaneously and in the proper order execute all of the field updates for each record in one cursor update. This can result in doubling your script speed for every field calculation you eliminate beyond your first calculation.

So for example the code below performs at least 2 times as fast as 3 separate field calculations. The number of row update operations and dependencies can be extended much longer than I have shown. I have to imagine a sample calculation for field1 and field2, since you do not indicate what they are, but any field calculation you may need to do can be translated to a cursor update, and often more elegantly:

import arcpy
from arcpy import env
env.workspace = "C:/dataPath/yourGDB.gdb"
fc = "YourFC"
arcpy.AddField_management(fc, "Field1", "Double")
arcpy.AddField_management(fc, "Field2", "Double")
arcpy.AddField_management(fc, "Field3", "Double")

fields = ['Name', 'Field1', 'Field2', 'Field3']

# Create update cursor for feature class 
with arcpy.da.UpdateCursor(fc, fields) as cursor:
    # For each row, do all 3 field updates in the proper order
    for row in cursor:
        # calculation of field1 and field2 below is just an example, 
        # and if they are based on the same input field conditions
        # you don't need to write them twice like you do with the field calculator.
        if row[0] == 'Name1':
            row[1] = 1
            row[2] = 2
        elif row[0] == 'Name2':
            row[1] = 2
            row[2] = 3
        # field1 and field2 are updated so now update field3
        row[3] = row[1] * row[2]
        cursor.updateRow(row)
  • @Hornbydd Thank you for this answer. I would have not preffered to use a python Script but in the end I figured that it was not possible to do what I wanted to do using Model Builder (without the aid of Python Scipts). – Jelle May 25 '15 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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