TableView (arcpy.mapping)

摘要

用于访问基本表属性。

讨论

TableView 对象对于管理地图文档 (.mxd) 中的独立表至关重要。它用于访问基本表属性(如数据源信息等)以及设置表的定义查询。除了 TableView 构造函数,ListTableViews 函数也能够引用 TableView 对象。

TableView 构造函数用于在工作空间内引用地图文档外的表。它能够使用 AddTableView 函数将外部表添加到地图文档中。此函数与 MakeTableView 相似,区别在于 MakeTableView 的结果不能永久添加到地图文档中。

ListTableViews 函数返回 TableView 对象的 Python 列表。随后,必须遍历列表中的每个项目,或指定一个索引号以引用具体的 TableView 对象。可在整个地图文档或特定数据框内搜索表。通配符还可用于限制搜索。

定义查询不适用于所有工作空间。使用不同工作空间时,应用正确的 SQL 语法非常重要。例如,文件地理数据库和 shapefile 的文件名都用双引号括起(例如,"文件名"),个人地理数据库的文件名都用方括号括起(例如,[文件名]),而 SDE 连接的文件名没有任何特殊字符(例如,文件名)。有关在地图文档或图层文件中更新工作空间和数据源的详细信息,请参阅使用 arcpy.mapping 更新和修复数据源帮助主题。

可以使用 RemoveTableView 函数从地图文档中移除表。

语法

TableView (table_view_data_source)
参数说明数据类型
table_view_data_source

A string that includes the full workspace path, including the name of the table.

String

属性

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

以表数据集在工作空间(非内容列表)中显示的方式返回其名称。

String
dataSource
(只读)

返回表的数据源路径。此属性包含 workspacePathdatasetName 的组合。

String
definitionQuery
(读写)

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

String
name
(读写)

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

String
isBroken
(只读)

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

Boolean
workspacePath
(只读)

返回表的工作空间或连接文件的路径。

String

方法概述

方法说明
findAndReplaceWorkspacePath (find_workspace_path, replace_workspace_path, {validate})

使用新工作空间路径替换表的工作空间

replaceDataSource (workspace_path, workspace_type, {dataset_name}, {validate})

替换地图文档 (.mxd) 中表的数据源,同时提供切换工作空间类型的功能(例如用 SDE 工作空间替换文件地理数据库工作空间)。

方法

findAndReplaceWorkspacePath (find_workspace_path, replace_workspace_path, {validate})
参数说明数据类型
find_workspace_path

A string that represents the workspace path or connection file you want to find. If an empty string is passed, then all workspace paths will be replaced with the replace_workspace_path parameter depending on the value of the validate parameter.

String
replace_workspace_path

A string that represents the workspace path or connection file you want to use to replace.

String
validate

If set to True, the workspace will only be updated if the replace_workspace_path value is a valid workspace. If it is not valid, the workspace will not be replaced. If set to False, the method will set the workspace to match the replace_workspace_path, regardless of a valid match. In this case, if a match does not exist, then the table's data source would be broken.

(默认值为 True)

Boolean

有关详细说明、参数信息、案例和编码示例,请参阅更新和修复数据源帮助主题。

replaceDataSource (workspace_path, workspace_type, {dataset_name}, {validate})
参数说明数据类型
workspace_path

A string that includes the workspace path to the new data or connection file.

String
workspace_type

A string keyword that represents the workspace type of the new data.

  • ACCESS_WORKSPACE A personal geodatabase or Access workspace
  • ARCINFO_WORKSPACE An ArcInfo coverage workspace
  • CAD_WORKSPACEA CAD file workspace
  • EXCEL_WORKSPACEAn Excel file workspace
  • FILEGDB_WORKSPACEA file geodatabase workspace
  • NONEUsed to skip the parameter
  • OLEDB_WORKSPACEAn OLE database workspace
  • PCCOVERAGE_WORKSPACEA PC ARC/INFO Coverage workspace
  • RASTER_WORKSPACEA raster workspace
  • SDE_WORKSPACEAn SDE geodatabase workspace
  • SHAPEFILE_WORKSPACEA shapefile workspace
  • TEXT_WORKSPACEA text file workspace
  • TIN_WORKSPACEA TIN workspace
  • VPF_WORKSPACEA VPF workspace
String
dataset_name

A string that represents the name of the table the way it appears in the new workspace (not the name of the table in the table of contents). If dataset_name is not provided, the replaceDataSource method will attempt to replace the dataset by finding a table with a the same name as the layer's current dataset property.

String
validate

If set to True, a workspace will only be updated if the workspace_path value is a valid workspace. If it is not valid, the workspace will not be replaced. If set to False, the method will set the workspace to match the workspace_path, regardless of a valid match. In this case, if a match does not exist, then the data source would be broken.

(默认值为 True)

Boolean

有参数信息、案例和代码示例等详细信息,请参阅更新和修复数据源帮助主题。

代码实例

TableView 示例 1

以下脚本将在名为 Transportation 的数据框中查找名为 Customers 的表并设置此表的定义查询。

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0]
for table in arcpy.mapping.ListTableViews(mxd, "", df):
    if table.name.lower() == "trafficaccidents":
        table.definitionQuery = "\"age\" >= 18"
mxd.save()
del mxd
TableView 示例 2

以下脚本引用文件地理数据库中的表并将此表添加到引用的地图文档中。

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0]
accidentsTable = arcpy.mapping.TableView(r"C:\Project\Data\Transportation.gdb\Accidents")
arcpy.mapping.AddTableView(df, accidentsTable)
mxd.saveACopy(r"C:\Project\Project2.mxd")
del mxd, accidentsTable
5/10/2014