AE实现不同图层的合并C#代码

 

今天在单位做图层合并的工作,刚开始找不到相应的接口,现在解决了,放出来与大家共享
本程序实现了对具有同类型数据结构的shapefile的图层合并,并在MapControl中显示.
            ILayer pLayer;
            IFeatureLayer pFeatureLayer;
            IFeatureClass pFeatureClass;
            IWorkspaceName pNewWSName;
            IBasicGeoprocessor pBasicGeop;
            IFeatureClassName pFeatureClassName;
            IDatasetName pDatasetName;
            IFeatureClass pOutputFeatClass;
            IFeatureLayer pOutputFeatLayer;
            IArray pArray;
            ITable pTable;
            //合并图层的集合
            pArray = new ArrayClass();
            for (int i = 0; i < this.axMapcontrol1.LayerCount;i++ )
            {
                pLayer = this.MapC_main.get_Layer(i);
                pArray.Add(pLayer);
            }
            //定义输出图层的fields表
            pLayer = this.MapC_main.get_Layer(0);
            pTable = (ITable)pLayer;
            pFeatureLayer=(IFeatureLayer)pLayer;
            pFeatureClass = pFeatureLayer.FeatureClass;
            //判断图层是否大于2个
            if(this..axMapcontrol1.LayerCount< 2){
                MessageBox.Show("Table QI failed");
                return;
            }
            //输出文件类型
            pFeatureClassName = new FeatureClassNameClass();
            pFeatureClassName.FeatureType = esriFeatureType.esriFTSimple;
            pFeatureClassName.ShapeFieldName = "Shape";
            pFeatureClassName.ShapeType = pFeatureClass.ShapeType;
            //输出shapefile的名称和位置
            pNewWSName = new WorkspaceNameClass();
            pNewWSName.WorkspaceFactoryProgID="esriDataSourcesFile.ShapefileWorkspaceFactory";
            pNewWSName.PathName = "E:\\Cshape";
            pDatasetName = (IDatasetName)pFeatureClassName;
            pDatasetName.Name = "Union_result_1";
            pDatasetName.WorkspaceName = pNewWSName;
            
            //合并图层
            pBasicGeop = new BasicGeoprocessorClass();
            pOutputFeatClass=pBasicGeop.Merge(pArray,pTable,pFeatureClassName);
            //Add the output layer to the map
            pOutputFeatLayer = new FeatureLayerClass();
            pOutputFeatLayer.FeatureClass = pOutputFeatClass;
            pOutputFeatLayer.Name = pOutputFeatClass.AliasName;
            this..axMapcontrol1.AddLayer(pOutputFeatLayer as ILayer, 0);
posted @   温景良(Jason)  Views(2406)  Comments(2Edit  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示