ArcGIS Pro 2.6 Model Builder: Calculate Field or Calculate Value Using Inline Variable Substitution

3231
6
08-04-2020 11:54 AM
by Anonymous User
Not applicable

I have a feature class that consists of county wide addresses that need to be exported to a .shp and then "Find & Replace" so all fields that have attributes with COUNTY ROAD, US HIGHWAY, STATE ROAD, STATE HIGHWAY to be changed to CO RD, US HWY, ST RD, ST HWY for a computer aided dispatch software to consume. 

This is usually a manual process, in which the .shp is kicked out and using the attribute tables capacity to mass "Find & Replace". But our system growing, having these types of tasks automated is going to be essential. 

So far in model builder getting the FC to .shp is obviously self explanatory, but the road block I have ran into is whether to use CALCULATE FIELD or CALCULATE VALUE and whether to use ITERATE FIELDS or ITERATE FIELD VALUES

 to iterate through two newly create .shp for Address Points and a Road Centerline that have mutiple fields which contain street name prefix types (eg. COUNTY ROAD, US HIGHWAY, STATE ROAD, STATE HIGHWAY) and convert them to a notation that our PD CAD software can cosume as mention above (eg. CO RD, US HWY, ST RD, ST HWY).

Using either CALCULATE FIELD or CALCULATE VALUE will obviously prompt me for a python expression that will perform an inline variable substitution, that being said which of the two tools would be best and what iterator would be best?

I have provided links to two examples where each of the tools is used to perform the "Find & Replace".

Attribute Value Correction Using ModelBuilder  

Getting Started with Model Builder | Map and Data Library 

Inline Variable Substitution Test Expression 

"%VALUE%".replace("Find", "Replace") OR !VALUE!.replace(%FIND%, %REPLACE%)

 

0 Kudos
6 Replies
ShitijMehta
Esri Regular Contributor

Hello Brian Acheff

From the description I understand you have a feature class/shapefile with few fields of interest say 3 fields. Each of these fields have some values that you need to alter to some other standard. 

So feature class A

Field1                                              Field 2

COUNTY ROAD                             COUNTY ROAD

US HIGHWAY                                 US HIGHWAY

you want to change it to something like this

Field1                                              Field 2

CO RD                                            CO RD

US HWY                                          US HWY     

Try this:

 

by Anonymous User
Not applicable

So if I have four fields that need to be iterated through and have their attributes changed, would it be best to use four "CALCULATE FILED" tools attached to the iterator; there are multiple fields that need to have their attributes match the desired text formatting or would it be better to use the Model Builder Utility Tool "CALCULATE VLAUE" which could possible go through all of the fields and change the text formatting? 

Also with having four different field is the "ITERATE FEATURE  SELECTION" the best or would "ITERATE FIELDS" or a different iterator be best.

All this being said and even though my Python proficiency needs to improve, would scripting in Python be the best route and if so would the scripting mimic the flow / syntax if I were using Model Builder?

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Current Model Variation:

0 Kudos
by Anonymous User
Not applicable

This is the error I keep getting, it says the OUTPUT from the FeatureClassToFeatureClass does not exist even though that is the first process that should take place, but it does perform the FeatureClassToFeatureClass; in addition would I have to set a precondition?

0 Kudos
by Anonymous User
Not applicable

Also I see that I would need to join the four outputs from the CALCULATE FIELD portion of the model since all of the updated data need to be in a single table that would eventually be exported to a .shp

0 Kudos
SiqiLi
by Esri Contributor
Esri Contributor

Hello Brian,

You could try to use two models:

  • SubModel uses Iterate Feature Selection to alter field values in one field.
  • MainModel uses Iterate Fields tool and SubModel to iterate through the four fields and alter values for each field.


Below is an example of the SubModel. This SubModel alters the values in FieldC. You'll need to set the Input Dataset, Field and the output of Calculate Field tool as model parameters. 

The MainModel uses Iterate Fields tool and SubModel. The MainModel iterates through the fields listed in the Field Name parameter and alter values in the fields. In each iteration, the Iterate Fields output Value stores the Field Name to be altered and passes the value to SubModel.

by Anonymous User
Not applicable

Siqi,

Would I need a 4 sub models, with preconditions combined into the comprehensive Sub Model in the Main Model, since the calculate field only applies to one field or could I use the calculate multiple fields.

I was able to get the model to run the way you showed, but involved only a single field being calculated in the Sub Model, the output did not update the text formatting, but rather changed all targeted values to <NULL>

0 Kudos