操作方法

操作方法:标注相关表

Last Published: March 10, 2023

摘要

提供的说明描述了如何使用 Python 标注相关表。 系统未提供“开箱即用”功能来标注相关表。

注: 需要基本了解 Python 函数和搜索光标。

过程

以下代码用于创建 FindLabel Python 函数。 不会创建关联,但会在两次迭代中比较两个关键字段。

  1. 打开标注表达式对话框。
    1. 右键单击要标注的要素类,然后选择属性
    2. 单击标注选项卡。
    3. 单击表达式以打开标注表达式对话框。
  2. 选择 Python 作为解析程序并选中高级复选框。
  3. 复制粘贴以下代码: 请注意,必须更改 [keyfield]、[FirstLabel]、key1、key2、L、L2 和 myDataTable 以匹配环境。
    • [keyfield]key1 是要素类中的关键字段,用于关联相关表。
    • [FirstLabel]L 是要标注的要素类中的字段。
    • key2 是相关表中的关键字段。
    • L2 是相关表中也应标记的字段。myDataTable 是相关表的路径和名称。
def FindLabel ([keyField], [FirstLabel]): import arcpy key1 = [keyField] # Key field in feature class key2 = "ID" # Key field in related table L = [FirstLabel] # Label field in feature class L2 = "Label2" # Label field in related table myDataTable = r"<path-to-related-table>" # Path to related table cur = arcpy.da.SearchCursor(myDataTable, [key2, L2]) for row in cur: if str(key1) == str(row[0]): L = L + " " + str(row[1]) return L
  1. 单击确定以返回到图层属性对话框。
  2. 单击应用以查看标注。

文章 ID:000012230

从 ArcGIS 专家处获得帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项

相关信息

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