操作方法

操作方法:在 ArcGIS Pro 中计算一个新字段以标识属性表的两个字段中的匹配值

Last Published: October 1, 2025

摘要

In some cases, when analyzing different fields for the same features in an attribute table, it is necessary to identify matching values in two fields. A new field can be created and calculated to reflect the noted comparison between the two fields. This article provides the instructions to do so in ArcGIS Pro. In this example, the comparison is made between the SOURCE and SOURCE_ED fields. The matching values are identified and populated in the new field, SOURCE_MATCH.

过程

  1. Add a new field to the attribute table.
    1. In the table, click Add Field The Add Field icon to add a new field to the attribute table.. The Fields view opens.
    2. In the Fields view, specify a name for the new field in the Field Name column. In this example, the new field is SOURCE_MATCH.
    3. Double-click the Alias column of the new field, and specify an alias for it. In this example, the alias is SOURCE_MATCH.
    4. Double-click the Data Type column of the new field, and select Text from the drop-down menu.
    5. On the top ribbon, on the Fields tab, click Save The Save button to save the newly created field in the attribute table..
  2. Calculate the new field to identify matching values in the two fields.
    1. Open the table, right-click the new field, and click Calculate Field. The Calculate Field window opens.
    2. In the Calculate Field window, for Input Table, select the table containing the fields to compare and the new field.
    3. For Field Name (Existing or New), select the new field created in Step 1. In this example, the field is SOURCE_MATCH.
    4. For Expression Type, select Python 3.
    5. Copy the following expression, and paste it in the Expression box. Replace !field1! and !field2! by double-clicking the two fields in the Fields list. In this example, the two fields are SOURCE and SOURCE_ED.
calc(!field1!,!field2!)
  1. Copy the following script, and paste it in the Code Block box:
def calc(field1 , field2):
    if field1 == field2 :
        return 'Yes'
    else:
        return 'No' 
Replace field1 and field2 with the two fields to be compared. In this example, field1 and field2 are replaced with SOURCE and SOURCE_ED respectively.
def calc(SOURCE , SOURCE_ED):
    if SOURCE == SOURCE_ED :
        return 'Yes'
    else:
        return 'No' 
  1. Click the Verify The Verify icon to verfiy the expression in the Calculate Field before running the tool. icon to validate the expression.
  2. Click Run.
The Calculate Field window containing the parameters and expression to calculate the new field with matching values from two fields in the attribute table.

The following image shows the new field containing the identified matching values from two existing fields in the attribute table.

The attribute table containing the new field containing the matching values from the two fields.

文章 ID: 000025230

接收通知并查找新问题或常见问题的解决方案

从我们全新的 AI 聊天机器人中获得简明答案和视频解决方案。

下载 Esri 支持应用程序

相关信息

发现关于本主题的更多内容

获取来自 ArcGIS 专家的帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项