Summary
In ArcGIS Pro, it is possible to replace all the values of a field with a default value. However, it is sometimes necessary to replace only certain values of the field for enhanced data accuracy and nuanced spatial analysis.
In this article, fields with a single '0' in the Distance field are replaced with '1' using an Arcade expression. The image below displays the attribute table with the field values to be replaced.
Procedure
- Open the ArcGIS Pro project.
- In the Contents pane, right-click the feature layer and click Attribute Table.
- In the attribute table, right-click the field name, and select Calculate Field. In this example, the Distance field is selected.
- In the Calculate Field window, specify the following parameters:
- For Input Table, ensure the layer selected in Step 2 is prefilled. In this example, the input table is test.
- For Field Name, ensure the field selected in Step 3 is prefilled. In this example, the field name is Distance.
- For Expression Type, select Arcade.
- For Expression, in the expression box, specify the expression provided below. Replace <field_name> with the name of the field that must be replaced with a specific value. Then, replace <initial_value> with the field value that must be replaced and <new_value> with the replacement field value.
if ($feature.<field_name> == '<initial_value>') {
Replace($feature.<field_name>, '<initial_value>', '<new_value>')
} else {
return($feature.<field_name>)
}
Note:
If numeric or date field values are used, remove the single quotes (' ') on <initial_value> and <new_value>.
- Click the Verify icon to validate the expression.
- Click OK to run the script.
The image below displays the new field values in the Distance field.