Field Calculator

Function Description: Used for calculating and editing fields in feature classes or tables. It allows users to write simple code to perform various calculations and operations, including calculating field values, updating field values, and calculating geometric properties.

Interface Layout and Corresponding Operations

As shown in the figure, the Field Calculator mainly consists of five parts: 1.Target Field Selection; 2.Expression Type Switching; 3.Field Preview; 4.Function Preview; 5.Expression Editing.

fieldCalculator.png

Target Field Selection

Click the dropdown box to select the field to be calculated. If you need to apply the expression to a new field, you can directly enter the name of the target field in the field dropdown box. If the current field does not exist after editing, a control will pop up to set the type of the new field, as shown:

fieldCalculator_addField.png

Expression Type Switching

You can choose between the Expression Interface or Python Script Interface for editing. The default view is the Expression Interface. The Python Script Interface is shown below:

fieldCalculator_python.png

Use the new button in the lower-left corner to create a new Python script, and use the delete button to remove scripts. After editing the Python expression, click the save button to save the changes to the script.

Field Preview

The list displays all available fields in the current layer. Double-clicking a field will automatically add it to the function editing area. If the currently selected field has valid values in the attribute table, you can select a valid value from the value area below the list, which will be automatically added to the function editing area upon clicking.

fieldCalculator_selectValue.png

Function Preview

The Field Calculator provides several built-in functions. You can enter the function name in the search box, and the required function will be automatically displayed. Click "Show Help" to view the function's usage instructions, methods, and examples. Similar to the Field Preview, double-clicking the function name will add it to the function editing area.

fieldCalculator_selectFun.png

Expression Editing

Expression editing in the Field Calculator supports two calculation methods: using built-in functions and basic operators or custom Python scripts.

Example 1: Modify the Value of a Field

Change the value of field "SCode" to the absolute value of the field "MCode" plus 1. First, select the field "SCode" in the field name section. Then, in the function expression editing area below, write the expression. After completing the expression, if it is valid, click "Apply" to complete the modification after the calculation is done.

fieldCalculator_demo1.png

Example 2: Use Python Expressions for Calculation

1.Write a Python script: This script calculates the sum of two numbers. After completing it, click the save button in the lower-right corner to use it in the Expression Interface.

fieldCalculator_demo1.png

Note: In the first line of the script, group='**Custom**', where Custom is the group name displayed in the function list.

fieldCalculator_demo1.png

2.After editing, it can be used in the Expression Editing page. In this example, use the twoSum function created in Step 1 to add fields T1 and T2, and assign the result to the newly created field T3.

fieldCalculator_demo1.png

results matching ""

    No results matching ""