Skip to main content

计算字段 (多个) (数据管理工具)

汇总

为要素类、要素图层或栅格计算两个或更多个字段的值。

用法

注意:

此工具会修改输入数据。 有关详细信息以及避免意外更改数据的策略,请参阅 修改或更新输入数据的工具

  • 要了解有关 Python 表达式的详细信息,请参阅 计算字段 Python 示例

    要了解有关 Arcade 表达式的详细信息,请参阅开发人员帮助中的 ArcGIS Arcade

    有关 SQL 表达式的详细信息,请参阅 SQL 表达式语法计算字段值

    要了解有关 VBScript 表达式的详细信息,请参阅 计算字段 VBScript 示例

  • 该工具的 Arcade 表达式使用 字段计算 Arcade 配置文件。 Arcade 配置文件是评估和理解 Arcade 表达式的上下文。 当对 Arcade 表达式进行求值时,返回值将转换为输出值的字段类型。

    注意:

    在 Windows 11 版本 24H2 中,VBScript 将成为一项按需特性,并且需要 VBScript 功能。

    要继续使用 VBScript 选项,请执行以下操作之一:

    • 将表达式类型转换为 Python、Arcade 或 SQL。

    • 在 Windows 系统设置中启用 VBScript 可选功能。

    有关详细信息,请参阅 移除和弃用通知

  • 使用所选要素集(如使用 创建要素图层按属性选择图层 工具从查询创建的要素集)时,此工具将只更新所选的记录。

  • 现有字段值将被覆盖。 要保留原始值,请创建输入表的副本作为备份,或者使用地理处理窗格中的 启用撤消 选项。

  • 对于 Python 计算,必须在字段名称两边添加惊叹号(例如 !fieldname!)。

    对于 Arcade 计算,字段名称必须以 $feature. 为前缀(例如,$feature.fieldname)。

    注:

    要在字段类型之间传递时间值(日期、仅日期、仅时间、时间戳偏移和文本),改用 转换时间字段 工具。

  • 计算文本或字符字段的字符串时,在对话框中,字符串必须使用双引号(例如 "string"),而在脚本中,还必须对使用双引号的字符串两边添加单引号(例如,'"string"')。

  • 要将字段计算为数值,请在表达式参数中提供数值,且值的两旁不加引号。

  • 您可以使用代码块参数来创建复杂表达式。 在对话框中直接提供代码块,或在脚本中将代码块作为字符串输入。 表达式与代码块会相互连接。 代码块必须返回与表达式的关联;代码块的结果必须传入到表达式中。

    只有 Python 表达式支持代码块参数。

  • 您可以在代码块参数中使用 Python math 模块及格式。 您还可以导入附加模块。 math 模块可提供数论函数与表达函数、幂函数与对数函数、三角函数、角度转换函数、双曲函数以及数学常数。 要了解更多有关 math 模块的内容,请参阅 Python 帮助。

  • 要在 Python 中计算几何信息,请使用 Geometry 对象属性。 例如,使用 !shape!.pointCount! 表达式计算要素中的折点数。

    注:

    计算几何属性 工具支持相似的计算。

    要在 Python 中计算面积和长度,请使用包含方法和单位类型的 getAreagetLength 方法。

    • 要以平方千米为单位计算面的测地线面积,请使用以下表达式:

      !shape!.getArea('GEODESIC', 'SQUAREKILOMETERS')!

    • 要以码为单位计算折线(或面)的平面长度,请使用以下表达式:

      !shape!.getLength('PLANAR', 'YARDS')

    有关详细信息,请参阅 ArcPy PolygonPolyline 对象。

    了解有关地理处理工具以及线性和面积单位的详细信息

  • 使用连接数据时,您仅可以更新源表中的字段。 您无法更新连接表中的字段。 要在连接表上执行计算,请直接在该表上执行计算。

  • 如果 Python 表达式尝试串连含有空值或者除数为零值的字符串字段,则会为该字段值返回空值。

  • SQL 表达式可用于加快要素服务的计算速度。 使用该表达式可以将单次请求设置为服务器,而不必一次执行一个要素或一行的计算,从而提高计算速度。

    仅要素服务支持 SQL 表达式。 对于其他格式,请使用 Python 或 Arcade 表达式。

    SQL 选项用于表达式类型参数具有以下限制:

参数

标注 说明 数据类型

输入表

包含将通过新的计算进行更新的字段的表。

Table View; Raster Layer; Mosaic Layer

表达式类型

指定要使用的表达式类型。

如果输入是要素服务,则默认表达式类型为 SQL。 对于任意其他类型的输入,默认表达式类型均为 Python

要了解有关 Python 表达式的详细信息,请参阅 计算字段 Python 示例

要了解有关 Arcade 表达式的详细信息,请参阅开发人员帮助中的 ArcGIS Arcade

有关 SQL 表达式的详细信息,请参阅 SQL 表达式语法计算字段值

要了解有关 VBScript 表达式的详细信息,请参阅 计算字段 VBScript 示例

  • Python将使用 Python 表达式类型。

  • Arcade将使用 ArcGIS Arcade 表达式类型。

  • SQL将使用 SQL 表达式类型。

  • VBScript(已弃用)将使用 VBScript 表达式类型。

String

字段

将计算的字段、要计算的表达式以及可选的 where 子句和字段类型。

将用于选择记录子集的可选 SQL 表达式。 仅计算与此 where 子句匹配的记录。 如果 where 子句留空,将计算所有记录。 有关 SQL 语法的详细信息,请参阅 在 ArcGIS 中使用的查询表达式的 SQL 参考

如果输入表中不存在具有指定名称的字段,则会添加该字段。 将使用字段类型值来设置字段的类型。 如果未指定字段类型,则该字段将添加为文本字段。

值表列:

  • Field Name (Existing or New)The field that will be updated with the new calculation. If a field with the specified name does not exist in the input table, it will be added.

  • ExpressionThe expression that will be used to create a value that will populate the selected rows.

  • Where ClauseThe SQL expression that will be used to select a subset of records.

  • Field TypeSpecifies the field type of the new field. This value is only used when the field name does not exist in the input table.

    • Short (16-bit integer)The field type will be short. Short fields support whole numbers between -32,768 and 32,767.

    • Long (32-bit integer)The field type will be long. Long fields support whole numbers between -2,147,483,648 and 2,147,483,647.

    • Big integer (64-bit integer)The field type will be big integer. Big integer fields support whole numbers between -(253) and 253.

    • Float (32-bit floating point)The field type will be float. Float fields support fractional numbers between -3.4E38 and 1.2E38.

    • Double (64-bit floating point)The field type will be double. Double fields support fractional numbers between -2.2E308 and 1.8E308.

    • TextThe field type will be text. Text fields support a string of characters.

    • DateThe field type will be date. Date fields support date and time values.

    • Date (high precision)The field type will be high precision date. High precision date fields support date and time values with millisecond time.

    • Date onlyThe field type will be date only. Date only fields support date values with no time values.

    • Time onlyThe field type will be time only. Time only fields support time values with no date values.

    • Timestamp offsetThe field type will be timestamp offset. Timestamp offset fields support a date, time, and offset from a UTC value.

    • BLOB (binary data)The field type will be BLOB. BLOB fields support data stored as a long sequence of binary numbers. You need a custom loader or viewer or a third-party application to load items into a BLOB field or view the contents of a BLOB field.

    • GUID (globally unique identifier)The field type will be GUID. GUID fields store registry-style strings consisting of 36 characters enclosed in curly brackets.

    • RasterThe field type will be raster. Raster fields can store raster data in or alongside the geodatabase. All ArcGIS software-supported raster dataset formats can be stored, but it is recommended that only small images be used.

Value Table

代码块

(可选)

用于复杂表达式的代码块。

此函数不能用于返回多个值。

String

强制域

(可选)

指定是否将强制执行字段属性域规则。

  • 选中将强制执行字段属性域规则。

  • 未选中将不会强制执行字段属性域规则。 这是默认设置。

Boolean

派生输出

标注 说明 数据类型

输出表

已更新的表。

Table View; Raster Layer; Mosaic Layer

环境

保留全局 ID

许可信息

  • 基本: 是
  • 标准: 是
  • 高级: 是