Select to view content in your preferred language

model builder tool to replace values of an attribute

6004
9
Jump to solution
06-23-2021 08:58 PM
Labels (2)
fred_bastian
Emerging Contributor

hello everyone,
i am using arcgis pro 2.4. I am trying to change the values of an attribute suing model builder calculate fiend tool. however, I am getting an error when I run the tool. Below is a screen shot of what i am using and getting error 000539. Any thoughts or suggestions on how i can overcome this would be highly appreciated.
 

fred_bastian_0-1624507048502.png

thank you.

0 Kudos
1 Solution

Accepted Solutions
fred_bastian
Emerging Contributor

This is the solution I worked out:

I ran the spatial joins and plain joins before manipulating the data. One thing to consider is the data type of the attribute to have its values replaced and the data type of the attribute to have its values compared to the first one. In this case the attribute to have the values changed is numeric and the other to be compared against is text. To be able to compare the 2 attributes they need to be of the same data type. So a new attribute has to be created with a text data type. Next the values from the original attribute are copied into the newly created attribute. Finally, the values can be replaced as required.  See below for screen shots.

1 - From the geoprocessing pane drag the "Add Field" tool from the data management tools.

fred_bastian_1-1624836549792.png

fred_bastian_3-1624836603173.png

2 - Once the new filed is created, drag a "Calculate Field" tool from the data management tools. Use expression type Arcade and then insert the attribute you want to copy values from right at the bottom by double clicking it in the "fields" list.

 

fred_bastian_4-1624836739765.png

fred_bastian_5-1624836810417.png

3 - Now that the values have been copied into the newly created attribute, drag another "Calculate Field" tool from the data management tools. This one will do the replacement of the values in the newly created attribute. By using the Arcade code expression right at the bottom. This uses the creation of a variable and a conditional "if" statement to find and replace values accordingly. PS - I had no null values in my data but if you do then you will need to adjust the statement to cater for nulls.

fred_bastian_6-1624836966775.png

fred_bastian_7-1624837141311.png

4 - Now that the data is comparable, drag a "Select" from the Analysis tools. Fill in the SQL expression and away you go...

fred_bastian_8-1624837357507.pngfred_bastian_9-1624837385789.png

Thank you to all who took the time to read and attempted to help.
Cheers.

 

 

 

 

View solution in original post

9 Replies
Waffle_House
Frequent Contributor

Screenshot of full error message?

0 Kudos
NABAZGHARIBMOHAMMED
Occasional Contributor

what you did is wrong. you have to write the in a function in Code Block section, then call it .
try this:

Fire_Risk_T=
replace_func(!Fire_Risk_T!,"1","HBLCA")

=====Code Block====
def replace_func(field, old_text,new_text):
    return field.replace(old_text,new_text)

 

Waffle_House
Frequent Contributor
JayantaPoddar
MVP Esteemed Contributor

I assume !Fire_Risk_T! field has a Text datatype. If not, please create a new field with Text DataType and use Field Calculator on that field.

Check the following expression

!Fire_Risk_T!.replace("1","HBLCA")


Think Location
fred_bastian
Emerging Contributor

hey thanks for your help.
I had done that already. In fact, I already finished creating the model and it works nicely!
Maybe I should document it here how I did it in case others come across the same problem.
thank you.

Nicole_Ueberschär
Esri Regular Contributor

That would be in fact helpful if you would share your solution here.

And then except it as solution so the post is marked as solved.

fred_bastian
Emerging Contributor

Hi Nicole,
I will reply with the solution detailed. Sorry, I had one of those moments when you lose it all and had to start from scratch again. Lucky I have a good memory and could put it together again. Stay tuned.

thanks.

0 Kudos
fred_bastian
Emerging Contributor

This is the solution I worked out:

I ran the spatial joins and plain joins before manipulating the data. One thing to consider is the data type of the attribute to have its values replaced and the data type of the attribute to have its values compared to the first one. In this case the attribute to have the values changed is numeric and the other to be compared against is text. To be able to compare the 2 attributes they need to be of the same data type. So a new attribute has to be created with a text data type. Next the values from the original attribute are copied into the newly created attribute. Finally, the values can be replaced as required.  See below for screen shots.

1 - From the geoprocessing pane drag the "Add Field" tool from the data management tools.

fred_bastian_1-1624836549792.png

fred_bastian_3-1624836603173.png

2 - Once the new filed is created, drag a "Calculate Field" tool from the data management tools. Use expression type Arcade and then insert the attribute you want to copy values from right at the bottom by double clicking it in the "fields" list.

 

fred_bastian_4-1624836739765.png

fred_bastian_5-1624836810417.png

3 - Now that the values have been copied into the newly created attribute, drag another "Calculate Field" tool from the data management tools. This one will do the replacement of the values in the newly created attribute. By using the Arcade code expression right at the bottom. This uses the creation of a variable and a conditional "if" statement to find and replace values accordingly. PS - I had no null values in my data but if you do then you will need to adjust the statement to cater for nulls.

fred_bastian_6-1624836966775.png

fred_bastian_7-1624837141311.png

4 - Now that the data is comparable, drag a "Select" from the Analysis tools. Fill in the SQL expression and away you go...

fred_bastian_8-1624837357507.pngfred_bastian_9-1624837385789.png

Thank you to all who took the time to read and attempted to help.
Cheers.

 

 

 

 

Nicole_Ueberschär
Esri Regular Contributor

Thanks for taking the time to document your solution!

0 Kudos