创建关系类 (数据管理)

许可等级:BasicStandardAdvanced

摘要

此工具可创建用于存储源表和目标表中字段或要素之间关联的关系类。

用法

语法

CreateRelationshipClass_management (origin_table, destination_table, out_relationship_class, relationship_type, forward_label, backward_label, message_direction, cardinality, attributed, origin_primary_key, origin_foreign_key, {destination_primary_key}, {destination_foreign_key})
参数说明数据类型
origin_table

与目标表相关联的表或要素类。

Table View
destination_table

与源表相关联的表。

Table View
out_relationship_class

创建的关系类。

Relationship Class
relationship_type

要在源表和目标表之间创建的关系类型。

  • SIMPLE两个独立对象之间的关系(父对父)。这是默认设置。
  • COMPOSITE两个相关对象之间的关系,其中一个对象的生存时间控制相关对象的生存时间(父对子)。
String
forward_label

用于在从源表导航至目标表时唯一识别关系的名称。

String
backward_label

用于在从目标表导航至源表时唯一识别关系的名称。

String
message_direction

消息在源表与目标表之间的传递方向。例如,在电线杆与变压器的关系中,当电线杆被删除时,会向与之相关的变压器对象发送一条消息,以告知它们该电线杆已被删除。

  • FORWARD将消息从源表传递到目标表。
  • BACK将消息从目标表传递到源表。
  • BOTH将消息从源表传递到目标表,然后再从目标表传递到源表。
  • NONE不传递任何消息。这是默认设置。
String
cardinality

确定在源表的行或要素与目标表的行或要素之间存在多少种关系。

  • ONE_TO_ONE源表中的每个行或要素可以与目标表中的零个或一个行或要素相关联。这是默认设置。
  • ONE_TO_MANY源表中的每个行或要素可与目标表中的一个或多个行或要素相关联。
  • MANY_TO_MANY源表中的多个字段或要素可与目标表中的一个或多个行或要素相关联。
String
attributed

指定关系是否具有属性。

  • NONE指示关系类将不具有属性。这是默认设置。
  • ATTRIBUTED指示关系类将具有属性。
Boolean
origin_primary_key

与关系类表中的“源外键”字段相关联的源表中的字段(通常指 OID 字段)。

String
origin_foreign_key

与源表中的“源主键”字段相关联的关系类表中的字段。

String
destination_primary_key
(可选)

与关系类表中的“目标外键”字段相关联的目标表中的字段(通常指 OID 字段)。

String
destination_foreign_key
(可选)

与目标表中的“目标主键”字段相关联的关系类表中的字段。

String

代码实例

创建关系类示例(Python 窗口)

以下 Python 窗口脚本演示了如何使用“创建关系类”工具。

import arcpy
arcpy.env.workspace = "C:/data/Habitat_Analysis.gdb"
arcpy.CreateRelationshipClass_management("vegtype", "vegtable", "veg_RelClass", "SIMPLE", "Attributes from vegtable", "Attributes and Features from vegtype", "NONE", "ONE_TO_ONE", "NONE", "HOLLAND95", "HOLLAND95")
创建关系类示例 1(独立脚本)

在植被要素类与包含附加植被信息的表之间创建关系类。

# Name: CreateRelationshipClass.py
# Description: Create a relationship class between vegetation feature
#                    class and table with additional vegetation information
# Author: ESRI

# import system modules 
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data"

# Copy vegtable.dbf to file gdb table, since both tables to be related
#  must be in the same database
vegDbf = "vegtable.dbf"
vegTbl = "Habitat_Analysis.gdb/vegtable"
arcpy.CopyRows_management(vegDbf, vegTbl)

# Create simple relationship class between 'vegtype' vegetation layer
#  and 'vegtable' table with additional vegetation information
veg = "Habitat_Analysis.gdb/vegtype"
relClass = "Habitat_Analysis.gdb/veg_RelClass"
forLabel = "Attributes from vegtable"
backLabel = "Attributes and Features from vegtype"
primaryKey = "HOLLAND95"
foreignKey = "HOLLAND95"
arcpy.CreateRelationshipClass_management(veg, vegTbl, relClass, "SIMPLE", forLabel, 
					      backLabel, "NONE", "ONE_TO_ONE", 
					     "NONE", primaryKey, foreignKey)
创建关系类示例 2(独立脚本)

在宗地要素类与包含所有者信息的表之间创建关系类。

# Name: CreateRelationshipClass.py
# Description: Create a relationship class between parcels feature
#                    class and table with owner information
# Author: ESRI

# import system modules 
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data"

# Copy owners.dat to file gdb table, since both tables to be related
#  must be in the same database
ownerDat = "owners.dat"
ownerTbl = "Montgomery.gdb/owners"
arcpy.CopyRows_management(ownerDat, ownerTbl)

# Create simple relationship class between 'parcel' parcel layer
#  and 'owner' table with additional parcel owner information
parcel = "Montgomery.gdb/Parcels"
relClass = "Montgomery.gdb/parcelowners_RelClass"
forLabel = "Owns"
backLabel = "Is Owned By"
primaryKey = "PROPERTY_ID"
foreignKey = "PROPERTY_I"
arcpy.CreateRelationshipClass_management(ownerTbl, parcel, relClass, "SIMPLE", forLabel, 
					     backLabel, "BACKWARD", "ONE_TO_MANY", 
					     "NONE", primaryKey, foreignKey)

环境

相关主题

许可信息

ArcGIS for Desktop Basic:否
ArcGIS for Desktop Standard:是
ArcGIS for Desktop Advanced:是
9/15/2013