Joining data

Joining data追加的字段来自一个或多个表。ArcGIS提供加入数据的几种方法,这取决于数据的来源和数据的基数。本主题介绍了可用的选项,以及如何决定哪个选项是最好的应用程序。


// Create the query definition.
IQueryDef queryDef = featureWorkspace.CreateQueryDef();

// Provide a list of tables to join.
queryDef.Tables = "streets, altname";

// Set the subfields and the WhereClause (in this case, the join condition).
queryDef.SubFields = "streets.NAME, streets.TYPE, altname.ST_NAME, altname.ST_TYPE";
queryDef.WhereClause = "streets.OBJECTID = altname.JOINID";

// Get a cursor of the results and find the indexes of the fields to display.
using (ComReleaser comReleaser = new ComReleaser())
{ 
  ICursor cursor = queryDef.Evaluate();
  comReleaser.ManageLifetime(cursor);
  int streetsNameIndex = cursor.FindField("streets.NAME");
  int streetsTypeIndex = cursor.FindField("streets.TYPE");
  int altnameNameIndex = cursor.FindField("altname.ST_NAME");
  int altnameTypeIndex = cursor.FindField("altname.ST_TYPE");

  // Use the cursor to step through the results, displaying the names and altnames of each 
 // street.
  IRow row = null;
  while ((row = cursor.NextRow()) != null)
  {
    Console.WriteLine("Street name: {0} {1}. - Alt. name: {2} {3}.", row.get_Value(streetsNameIndex),
      row.get_Value(streetsTypeIndex), row.get_Value(altnameNameIndex), row.get_Value(altnameTypeIndex));
  }
}

// Make the new TableQueryName.
IQueryName2 queryName2 = (IQueryName2)new TableQueryNameClass();
queryName2.QueryDef = queryDef;
queryName2.PrimaryKey = "streets.StreetID";
queryName2.CopyLocally = true;

// Set the workspace and name of the new QueryTable.
IDatasetName datasetName = (IDatasetName)queryName2;
datasetName.WorkspaceName = workspaceName;
datasetName.Name = "StreetsJoin";

// Open the virtual table.
IName name = (IName)queryName2;
ITable table = (ITable)name.Open();




// Build a memory relationship class.
Type memRelClassFactoryType = Type.GetTypeFromProgID("esriGeodatabase.MemoryRelationshipClassFactory");
IMemoryRelationshipClassFactory memRelClassFactory = (IMemoryRelationshipClassFactory)Activator.CreateInstance(memRelClassFactoryType);
IRelationshipClass relationshipClass = memRelClassFactory.Open("ParcelsOwners", parcelsFeatureClass,
       "PARCEL_ID", (IObjectClass)ownersTable, "PARCEL_ID", "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);


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值