arcgis engine中图层与数据表之间的join操作
在进行join之前,请确认数据库可以连接
try
{
//使用oledb连接数据库,连接到sys.基本信息表
IWorkspaceFactory pWorkspaceFactory = new OLEDBWorkspaceFactory();
IPropertySet pPropSet = new PropertySet();
pPropSet.SetProperty("CONNECTSTRING","Provider=sqloledb;Data Source=" + this.instanceBox.Text + ";Initial Catalog=sys;User Id=sa;Password=sa;");
IWorkspace pWorkspace = pWorkspaceFactory.Open(pPropSet,0);
IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
ITable pForeignTable = pFeatureWorkspace.OpenTable("sys.基本信息表");
//打开已经修复好数据源的temp.mxd
IMapDocument pMapDocument = new MapDocumentClass();
pMapDocument.Open(startPath + @"\temp.mxd",null);
IMap pMap = pMapDocument.get_Map(0);
//获取图层
ILayer pLayer = null;
for (int i = 0; i < pMap.LayerCount; i++)
{
if (pMap.get_Layer(i).Name == "点位")
{
pLayer = pMap.get_Layer(i);
}
}
if (pLayer == null)
{
MessageBox.Show("打开地图文件(.mxd)失败");
return;
}
//join
IFeatureLayer pFLayer = (IFeatureLayer)pLayer;
IFeatureClass pFClass2 = pFLayer.FeatureClass;
IMemoryRelationshipClassFactory pMemRelClassFactory = new MemoryRelationshipClassFactoryClass();
IRelationshipClass pRelaClass = pMemRelClassFactory.Open("TableJoin1",pFClass2,"点位编号",(IObjectClass)pForeignTable,"点位编号","forward","backward",esriRelCardinality.esriRelCardinalityOneToOne);
IDisplayRelationshipClass pDisplayRelationshipC = (IDisplayRelationshipClass)pFLayer;
pDisplayRelationshipC.DisplayRelationshipClass(pRelaClass,esriJoinType.esriLeftOuterJoin);
pMapDocument.Save(false,true);
pMapDocument.Close();
}
catch (System.Exception ex4)
{
MessageBox.Show(ex4.Message);
return;
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/rrrrssss00/archive/2008/11/07/3244840.aspx