关系类处理专题之创建关系类|RelationShipClass
阅读原文时间:2023年07月08日阅读:3

///

/// 存在于数据库中的数据集中 ///
/// 数据库路径
/// 源要素类的名称
/// 目标要素类的名称
/// 所在数据集的名称
/// 生成的关系类的名称
/// 源表主键
/// 源表外键
/// 是否复合关系
public void createRelationShipClass(string mdbPath, string ORIFClassName, string DESFClassName, string DatasetName, string newRSClassName, string PrimaryKey, string ForeignKey, bool isComposite)
{
IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(mdbPath, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClassORI = pFeatureWorkspace.OpenFeatureClass(ORIFClassName);
IFeatureClass pFeatureClassDES = pFeatureWorkspace.OpenFeatureClass(DESFClassName);
IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(DatasetName);
IRelationshipClassContainer pRSCContainer = pFeatureDataset as IRelationshipClassContainer;

        IRelationshipClass pRelationshipClass = pRSCContainer.CreateRelationshipClass(  
            newRSClassName,   //生成的关系类的名称  
            pFeatureClassORI,   // 参与生成的源要素类/表  
            pFeatureClassDES,   //参与生成的目标要素类/表  
            "",  
            "",  
            esriRelCardinality.esriRelCardinalityOneToMany,  //表间关系  
            esriRelNotification.esriRelNotificationForward,  //通知???  
            isComposite,          //是否复合关系  
            false,        //是否添加属性表  
            null,        //字段集信息  
            PrimaryKey,     //源表主键  
            "",  
            ForeignKey,     //源表外键  
            "");  
    }  
    /\*测试数据\*\*\*\*\*  
        string mdbPath = "c:/Users/Administrator/Desktop/GXLTest.mdb";  
        string ORIFClassName="zd";  
        string DESFClassName="zrz";  
        string DatasetName="GXL";  
        string newRSClassName="relation1";  
        string PrimaryKey="zddm";  
        string ForeignKey = "zddm";  
        bool isComposite = true;  
        createRelationShipClass(mdbPath,ORIFClassName,DESFClassName,DatasetName,newRSClassName,PrimaryKey,ForeignKey,isComposite);  
    \*/

使用测试文件

提取密码:3td1

创建完成之后,在Arcmap中删除zd中的图块,则他所对应的zrz图块也随之删除