操作方法
在 ArcGIS Pro 中,可以使用字段工具集中的工具根据字段对任何地理数据库表或要素类的相关表进行标注。 本文提供了通过在 ArcGIS Pro 中运行 ArcPy 脚本,使用字段工具集中的工具标注相关表的工作流。
def FindLabel (<keyField1>, <firstLabel>): import arcpy key1 = <keyField1> # The key field in the feature class key2 = "<keyField2>" # The key field in the related table L = <firstLabel> # The label field in the feature class L2 = "<label2>" # The label field in the related table myDataTable = r"<path-to-related-table>" # The related table file path cur = arcpy.da.SearchCursor(myDataTable, [key2, L2]) for row in cur: if str(key1) == str(row[0]): L = L + " " + str(row[1]) return L
以下代码块演示了完整的工作脚本。
def FindLabel ([ENAME], [CNAME]): import arcpy key1 = [ENAME] # Key field in feature class key2 = "District" # Key field in related table L = [CNAME] # Label field in feature class L2 = "Population" # Label field in related table myDataTable = r"C:\Users\IDT27\Documents\Artwrk\29840\HKPOP\HKPOP.gdb\HK2016_Census_csv" # 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
获取来自 ArcGIS 专家的帮助
下载 Esri 支持应用程序