Table

摘要

用于对基本表属性和方法进行访问。

说明

有两种方法可以在脚本中引用表以用于工程。 要引用工程中已有的表,请在 Map class 上使用 listTables 方法。 要直接从工作空间引用表,请使用 Table 函数。 您可能希望使用 listTables 函数引用工程中的表,因为您可能需要更改表的数据源或定义查询,甚至使用 MapremoveTable 方法从工程中删除表。 Table 函数对于引用要添加到工程中的新表很有用。 获取到新的外部表源的引用后,可以利用 addTable 方法将其添加到地图中。

表可以支持零到多个定义查询,但只能激活一个定义查询。 也有可能存在一个或多个定义查询但没有一个是活动的。 有几种方法可以管理定义查询。 第一种方式,可以使用 definitionQuery 属性。 如果在不具有定义查询的表或具有多个定义查询的表上设置唯一 SQL 字符串,则会添加新定义查询并将其设置为活动查询。 如果在具有相同查询的表上设置 SQL 字符串,则会将其设置为活动定义查询(如果它尚未处于活动状态)。 管理定义查询的第二种方法是结合使用 listDefinitionQueriesupdateDefinitionQueries 函数。 listDefinitionQueries 函数会返回一个 Python 字典列表,这些字典展示了每个查询关联的属性。 字典关键字是 namesqlisActive。 可以使用核心 Python 方法在 Python 列表中添加、修改或移除定义查询。 可以将字典 isActive 值设置为 True 以设置活动查询。 同样,只有一个查询可以处于活动状态。 如果您尝试将多个查询设置为活动状态,则会返回错误。 更改完成后,使用 updateDefinitionQueries 函数设置新的更改。

使用 enableTime 方法可以在表上启用时间功能。 时间功能启用后,time 属性允许访问 LayerTime 对象,并进一步配置表的时间属性。 有关表的代码示例,请参阅 LayerTime 帮助主题。

可以在 Layout 上使用 TableFrameElement 类来展示和配置表中的字段和行。 要创建表框架,请在 Layout 类上使用 createTableFrameElement 方法。 有关详细信息和代码示例,请参阅 TableFrameElement 类的帮助主题。

更改表的数据源是一项常见要求。 有关详细说明、参数信息、案例和代码示例,请参阅更新和修复数据源帮助主题。

属性

属性说明数据类型
connectionProperties
(只读)

将表的数据源连接信息返回为 Python 字典。

Dictionary
dataSource
(只读)

返回表的数据源的完整路径。 其中包括完整的工作空间路径和数据集的名称。 对于企业级地理数据库表,将返回包含表的连接信息的字符串。

提示:

ArcGIS Pro 工程中的企业级地理数据库表不保留用于创建图层的数据库连接文件的路径 (.sde)。

String
definitionQuery
(可读写)

用于获得或设置表的定义查询。

String
isBroken
(只读)

如果表的数据源已损坏,则返回 True

Boolean
isTimeEnabled
(只读)

指示在表上是否启用时间。 如果 isTimeEnabled 属性返回 True,则可以使用表上的 time 属性返回 LayerTime 对象。 如果未启用时间,请在包含时间信息的表上使用 enableTime 方法。

Boolean
longName
(只读)

表的全名,包括图层组信息(如果存在)。 例如,位于名为 'Group Layer' 的组图层中的名为 'Table' 的表,将返回 longName 值 'Group Layer\\Table'。 如果表不在组中,则 longName 将与 name 值相同。

String
metadata
(可读写)

获取或设置表格的元数据类信息。

注:
设置元数据取决于 isReadOnly 属性值。

Metadata
name
(可读写)

用于以表在内容列表中显示的方式设置或获得表名称。 可包含空格。

String
time
(只读)

如果在表上启用了时间,则返回一个 LayerTime 对象。

注:

LayerTime 对象具有可用于 LayerTable 对象的时间属性。

LayerTime
URI
(只读)

表的统一资源指示符。 这是工程中表的唯一标识符,使用 Python CIM 访问时有时需要它。 添加表并建立 URI 后,该值不会随时间变化。 例如,如果您修改表的名称,则 URI 不会更改。

String

方法概述

方法说明
disableTime ()

禁用 Table 对象上启用时间的属性。

enableTime ({startTimeField}, {endTimeField}, {autoCalculateTimeRange}, {timeDimension})

如果表具有时间信息,则在该表上启用时间。

getDefinition (cim_version)

获取表格 CIM 定义。

getSelectionSet ()

以 Python 对象 ID 集的形式返回表选择。

listDefinitionQueries ({wildcard})

返回与表关联的定义查询的 Python 列表。

saveACopy (file_name)

将表保存为图层文件 (.lyrx)。

setDefinition (definition_object)

设置表的 CIM 定义。

setSelectionSet ({oidList}, {method})

使用 Python 对象 ID 列表设置表选择。

updateConnectionProperties (current_connection_info, new_connection_info, {auto_update_joins_and_relates}, {validate}, {ignore_case})

updateConnectionProperties 方法使用工作空间字典或路径替换连接属性。

updateDefinitionQueries (definitionQueries)

更新表的定义查询集合。

方法

disableTime ()

enableTime 方法可用于重新启用时间属性。

enableTime ({startTimeField}, {endTimeField}, {autoCalculateTimeRange}, {timeDimension})
参数说明数据类型
startTimeField

The name of the field containing the start time values. If each row has a single time field, specify that field name in the startTimeField and leave endTimeField blank. If each row has a start and end time field, specify both the startTimeField and endTimeField.

(默认值为 None)

String
endTimeField

The name of the field containing the end time values. Not all tables use an end time field. If each row has a single time field, specify that field name in the startTimeField and leave endTimeField blank. If each row has a start and end time field, specify both the startTimeField and endTimeField.

(默认值为 None)

String
autoCalculateTimeRange

If set to True, the start and end time attribute information is used to calculate the table's time extent.

(默认值为 True)

Boolean
timeDimension

The name of the dimension containing time values when using netCDF data.

(默认值为 None)

String

enableTime 方法的所有参数均为可选参数。 如果未指定 startTimeFieldendTimeField,则该方法将评估数据并尝试提供适当的默认值。

运行 enableTime 方法后,可以使用表上的 time 属性返回 LayerTime 对象。 如果布局上的 MapFrame 包含启用时间的图层或表,则可以使用 MapTime 类访问地图时间设置。

getDefinition (cim_version)
参数说明数据类型
cim_version

A string that represents the major version of the CIM.

String

ArcGIS Pro 2.4 中引入了对其他对象属性的 CIM 级别访问权限。 要返回对象的 CIM 定义,必须指定 cim_version。 Esri 遵循语义版本规范。 这意味着在主要版本(例如 3.0)中允许突破性 API 更改。 如果可能在新版本中引入突破性更改,Python 脚本作者可通过该值控制脚本运行期间使用的 CIM 版本。 如果您正在为 ArcGIS Pro 2.x 创作脚本,可将 cim_version 指定为 'V2'。 如果您正在为 ArcGIS Pro 3.x 创作脚本,可将 cim_version 指定为 'V3'。 使用 cim_version 'V2' 创作的脚本可继续在 ArcGIS Pro 3.x 中使用。

有关使用 CIM 和示例的详细信息,请参阅 Python CIM 访问

getSelectionSet ()
返回值
数据类型说明
List

以 Python 对象 ID 集的形式返回表选择。

提供检索表当前选择的简便方式。

listDefinitionQueries ({wildcard})
参数说明数据类型
wildcard

A wildcard is based on the query name and is not case sensitive. A combination of asterisks (*) and characters can be used to limit the resulting list.

(默认值为 None)

String
返回值
数据类型说明
List

表示与每个查询关联的属性的 Python 字典列表。 字典关键字是 namesqlisActive

可以使用标准做法从 Python 列表中添加、修改或删除定义查询。 可以将字典 isActive 值设置为 True 以设置活动查询。 同样,只有一个查询可以处于活动状态。 如果您尝试将多个查询设置为活动状态,则会返回错误。 更改完成后,使用 updateDefinitionQueries 函数设置新的更改。

saveACopy (file_name)
参数说明数据类型
file_name

A string that includes the location and name of the output layer file (.lyrx).

String

表和图层可保存到图层文件 (.lyrx)。

setDefinition (definition_object)
参数说明数据类型
definition_object

使用 getDefinition 最初检索的已修改 CIM 定义对象。

Object

有关使用 CIM 和示例的详细信息,请参阅 Python CIM 访问

setSelectionSet ({oidList}, {method})
参数说明数据类型
oidList
[oidList,...]

与相应的选择方法一起使用的 Python 对象 ID 列表。

(默认值为 None)

List
method

用于指定要使用的选择方法的字符串。

  • NEWoidList 创建一个新的记录选择。
  • DIFFERENCE选择不在当前选择中但在 oidList 中的记录。
  • INTERSECT选择当前选择和 oidList 中均含有的记录。
  • SYMDIFFERENCE选择当前选择或 oidList 中包含的记录。
  • UNION选择当前选择和 oidList 中的全部记录。

(默认值为 NEW)

String

利用此方法可方便管理表选择。要清空选择,请使用包含空列表的 NEW 选择方法或不设置任何参数。Python 列表可用于 oidList,但会针对 Table 对象使用 getSelectionSet 方法返回集。

updateConnectionProperties (current_connection_info, new_connection_info, {auto_update_joins_and_relates}, {validate}, {ignore_case})
参数说明数据类型
current_connection_info

A string that represents the workspace path or a Python dictionary that contains connection properties to the source you want to update. If an empty string or None is used in current_connection_info, all connection properties will be replaced with the new_workspace_info, depending on the value of the validate parameter.

String
new_connection_info

A string that represents the workspace path or a Python dictionary that contains connection properties with the new source information.

String
auto_update_joins_and_relates

If set to True, the updateConnectionProperties method will also update the connections for associated joins or relates.

(默认值为 True)

Boolean
validate

If set to True, the connection properties will only be updated if the new_connection_info value is a valid connection. If it is not valid, the connection will not be replaced. If set to False, the method will set all connections to match the new_connection_info value, regardless of a valid match. In this case, if a match does not exist, the data sources would be broken.

(默认值为 True)

Boolean
ignore_case

Determines whether searches will be case sensitive. By default, queries are case sensitive. To perform queries that are not case sensitive, set ignore_case to True.

(默认值为 False)

Boolean

有关更详细的说明、参数信息、情景和代码示例,请参阅更新和修复数据源

updateDefinitionQueries (definitionQueries)
参数说明数据类型
definitionQueries
[definitionQueries,...]

Updates a list of dictionaries that represent the properties of each definition query for a table.

List

此函数通常用于应用对 listDefinitionQueries 函数返回的结果所做的更改。

代码示例

Table 示例 1

以下脚本为所有地图中的所有表打印具有损坏数据源的独立表名称:

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
for m in aprx.listMaps():
    for tbl in m.listTables():
        if tbl.isBroken:
            print(f"Table: {tbl.name} is broken in map: {m.name}")
del aprx
Table 示例 2

以下脚本将文件地理数据库中的表添加到地图中:

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
addTab = arcpy.mp.Table(r"C:\Projects\YosemiteNP\Data_Vector\YosemiteData.gdb\NHDFCode")
m = aprx.listMaps("Yose*")[0]
m.addTable(addTab)
del aprx