• Join Attributes


    1.

    IWorkspaceFactory2 workspaceFactory = new ShapefileWorkspaceFactoryClass() as IWorkspaceFactory2;
    
                IWorkspace workspace = workspaceFactory.OpenFromFile(@"E:", 0);
    
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
    
                IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(“a”);
    
                IFeatureClass featureClass2 = featureWorkspace.OpenFeatureClass( "b");
    
     
    
                AddJoin aj = new AddJoin();
    
                aj.in_field = "ID";
    
                aj.in_layer_or_view = featureClass2; // @"E:jhl" + Functions.g_ROAD + "_SpatialJoin";
    
                aj.join_field = "FID";
    
                aj.join_table = @"E:a.shp";
    
                //aj.out_layer_or_view = Functions.g_ROAD + "_SpatialJoin";
    
                aj.join_type = "KEEP_ALL";
    
                Geoprocessor gp = new Geoprocessor();
    
                //gp.OverwriteOutput = true;
    
                gp.Execute(aj, null);

     

    2.

    //// Build a memory relationship class.
    
                Type memRelClassFactoryType =Type.GetTypeFromProgID("esriGeodatabase.MemoryRelationshipClassFactory");
    
                IMemoryRelationshipClassFactory memRelClassFactory = (IMemoryRelationshipClassFactory)Activator.CreateInstance(memRelClassFactoryType);
    
                IRelationshipClass relationshipClass = memRelClassFactory.Open("a", featureClass2, "ID", (IObjectClass)featureClass,
    
                    "FID", "Is Owned By", "Owns",esriRelCardinality.esriRelCardinalityOneToOne);
    
                // Open the RelQueryTable as a feature class.
    
                Type rqtFactoryType =Type.GetTypeFromProgID("esriGeodatabase.RelQueryTableFactory");
    
                IRelQueryTableFactory rqtFactory = (IRelQueryTableFactory)Activator.CreateInstance(rqtFactoryType);
    
                ITable relQueryTable = (ITable)rqtFactory.Open(relationshipClass, false, null,null, string.Empty, false, false);

     

    3.

                

    // Create the query definition.
    
                IQueryDef queryDef = featureWorkspace.CreateQueryDef();
    
                // Provide a list of tables to join.
    
                queryDef.Tables = "a,b";
    
                queryDef.Tables += "";
    
                // Set the subfields and the WhereClause (in this case, the join condition).
    
                queryDef.SubFields = "*";
    
                queryDef.WhereClause = "a.ID = b.FID + 1";
    
     
    
                // Make the new TableQueryName.
    
                IQueryName2 queryName2 = (IQueryName2)new TableQueryNameClass();
    
                queryName2.QueryDef = queryDef;
    
                queryName2.PrimaryKey = "ID";
    
                queryName2.CopyLocally = true;
    
     
    
                IDataset workspaceDataset = (IDataset)featureWorkspace;
    
                IWorkspaceName workspaceName = (IWorkspaceName)workspaceDataset.FullName;
    
     
    
                // Set the workspace and name of the new QueryTable.
    
                IDatasetName datasetName = (IDatasetName)queryName2;
    
                datasetName.WorkspaceName = workspaceName;
    
                datasetName.Name = "Join";
    
     
    
                // Open the virtual table.
    
                IName name = (IName)queryName2;
    
                ITable table = (ITable)name.Open();

     

  • 相关阅读:
    如何改变checkbox的样式
    EChart.js 简单入门
    Javascript异步编程的4种方法
    手写手机网站
    Handlebars的基本用法
    装饰器
    using Newtonsoft.Json;
    chrome插件学习笔记
    绩效考核如何快速评分
    wx jssdk
  • 原文地址:https://www.cnblogs.com/jhlong/p/5394524.html
Copyright © 2020-2023  润新知