Ejemplo n.º 1
0
        private bool ExportLayers(IMapDocument mapDoc, string strGdbName, bool bLayerSpatial)
        {
            //打开GDB工作空间
            ClsGDBDataCommon cls = new ClsGDBDataCommon();
            //IWorkspace wks = (IWorkspace)cls.OpenFromFileGDB(strGdbName);
            IWorkspace2 wksFeature = (IWorkspace2)cls.OpenFromFileGDB(strGdbName);

            if (wksFeature == null)
            {
                return(false);
            }

            IWorkspaceFactory pWSF      = new RasterWorkspaceFactoryClass();
            IWorkspace        wksRaster = pWSF.OpenFromFile(System.IO.Path.GetDirectoryName(mapDoc.DocumentFilename), 0);

            if (wksRaster == null)
            {
                return(false);
            }

            for (int i = 0; i < mapDoc.MapCount; i++)
            {
                IMap map = mapDoc.get_Map(i);
                if (map == null)
                {
                    continue;
                }
                ILayer     layer      = null;
                IEnumLayer pEnumLayer = map.get_Layers(null, true);
                pEnumLayer.Reset();
                while ((layer = pEnumLayer.Next()) != null)
                {
                    //只导出可见图层
                    if (chkExportVisible.Checked == true)
                    {
                        if (layer.Visible == false)
                        {
                            map.DeleteLayer(layer);
                            continue;
                        }
                    }

                    this.labelExport.Text = "导出:" + layer.Name;
                    this.labelExport.Refresh();
                    if (layer is IFeatureLayer)
                    {
                        IFeatureClass featureClassNew = CopyFeatureClassToWorkspace(map, layer, wksFeature, bLayerSpatial);
                        if (featureClassNew != null)
                        {
                            //拷贝完成重设数据源
                            cls.SetdataSourceOfFeatureLayer(layer, featureClassNew);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else if (layer is IRasterLayer)
                    {
                        IRasterDataset rasterDatasetNew = CopyRasterToWorkspace(map, layer, wksRaster, bLayerSpatial);
                        if (rasterDatasetNew != null)
                        {
                            //拷贝完成重设数据源
                            IRasterLayer rasterLayer = layer as IRasterLayer;
                            rasterLayer.CreateFromDataset(rasterDatasetNew);
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
            this.labelExport.Text = "导出完成!";
            return(true);
        }