矢量图层合并

本程序实现了对具有同类型数据结构的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.MapC_main.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.MapC_main.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.MapC_main.AddLayer(pOutputFeatLayer as ILayer, 0);

转载于:https://www.cnblogs.com/mynama/archive/2008/05/24/1206346.html

你可能感兴趣的:(矢量图层合并)