ArcGIS Engine 加载拓扑分析结果

   很多时候ArcGIS 拓扑分析完成后的拓扑图层需要再次加载到MapControl中,网上又很难找到相关代码片段。在研究了相关ArcObject类和接口后。

1、首先要明确在MDB与GDB中的DataSet数据集的数据加载原理:IFeatureClassContainer;和ITopologyContainer容器接口分别存放对应的要素集和拓扑集。也就是第一步获取对应的数据容器,通过容器获取需要的数据。

2、由于ITopologyContainer中获取到的是ITopology,ITopology不能直接加载到MapControl中,需要通过ITopologyLayer进行转换。PS:ITopologyLayer 继承了ILayer接口。

3、通过ILayer将拓扑分析结果加到MapControl中

分享拓扑图层加载代码:(从GDB中的数据集中加载拓扑图层,MDB )

   private void 加载数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FileGDBWorkspaceFactory fac = new FileGDBWorkspaceFactory();
            IWorkspace pWorkspace = fac.OpenFromFile(System.Windows.Forms.Application.StartupPath + "\\test.gdb", 0); 
 IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace; 
 
 IFeatureDataset pFeatureDataSet = pFeatureWorkspace.OpenFeatureDataset("abc"); 
 IFeatureClassContainer pFeatureclassContainer = (IFeatureClassContainer)pFeatureDataSet;

//加载拓扑结果关键代码
 ITopologyContainer ptopoContainer = (ITopologyContainer)pFeatureDataSet;

 ITopology topo=  ptopoContainer.get_TopologyByName("testTopo3");

if(topo!=null)

{
 ITopologyLayer topolayer = new TopologyLayerClass();
            topolayer.Topology=topo;
            ILayer topolayer11 = topolayer as ILayer;
 axMapControl1.AddLayer(topolayer11, 0);

}

//加载完成
 IEnumFeatureClass pEnumFeatureClass = (IEnumFeatureClass)pFeatureclassContainer.Classes; 
 IFeatureClass pFeatureClass = (IFeatureClass)pEnumFeatureClass.Next(); 
 while (pFeatureClass != null)//在每一个数据集中遍历数据层IFeatureClass 
 {
    
     IFeatureLayer pFLayer = new FeatureLayerClass();

     pFLayer.FeatureClass = pFeatureClass;
     //guanlian tu ceng he yao su ceng
     pFLayer.Name = pFeatureClass.AliasName;

     ILayer pLayer = pFLayer as ILayer;

    axMapControl1.AddLayer(pLayer, axMapControl1.LayerCount);

     pFeatureClass = (IFeatureClass)pEnumFeatureClass.Next(); 
 } 

}

效果如下图:




阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

ArcGIS Engine 加载拓扑分析结果

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭