ArcGIS AddIN开发:如何调用ArcMap中的选择工作空间的窗体

示例代码如下:

 public static IWorkspaceName BrowseWorkspace(int hwnd,out IWorkspace ws)
        {
            IGxObjectFilterCollection ipFilters = new GxDialogClass();
            //IGxObjectFilter ipFilter1 = new GxFilterFeatureDatasetsClass();  //要素数据集 ,导出时,IFeatureClassConverter对象无法写入Dataset中,此处隐藏掉
            //ipFilters.AddFilter(ipFilter1,false);
            IGxObjectFilter ifilt2 = new GxFilterWorkspacesClass();  //数据库工作空间,此类比较含糊,不知道具体指啥
            ipFilters.AddFilter(ifilt2,false);
            IGxObjectFilter ipFilter3 = new GxFilterFileFolderClass();  //文件工作空间
            ipFilters.AddFilter(ipFilter3,false);


            IGxDialog pGDialog = (IGxDialog)ipFilters;
            pGDialog.RememberLocation = true;
            pGDialog.Title = "请选择工作空间";
            pGDialog.AllowMultiSelect = false;

            IEnumGxObject pResultEnum = null;
            //IWorkspace ws = null;
            ws = null;
            IWorkspaceName wsn = null;
            if (pGDialog.DoModalOpen(hwnd, out pResultEnum) && pResultEnum != null)
            {
                IGxObject gxObj = pResultEnum.Next();
                if (gxObj is IGxDatabase)
                {
                    IGxDatabase gxDB = gxObj as IGxDatabase;
                    if (gxDB != null)
                    {
                        ws = gxDB.Workspace;
                        wsn = gxDB.WorkspaceName;
                    }  
                }
                else if (gxObj is IGxFolder)
                {
                    //Todo: figure out how to decide which workspace to get for
                    // a particular folder (shapefile, raster etc.)                    
                    //IEnumName enumName = ((IGxFolder)gxObj).FileSystemWorkspaceNames;

                    // for now just assume we want a shapefile ...
                    IWorkspaceFactory wsf = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
                    ws = wsf.OpenFromFile(((IGxFile)gxObj).Path, hwnd);
                    IDataset pOutDataset = ws as IDataset;
                    wsn = pOutDataset.FullName as IWorkspaceName;
                }
                else if (gxObj is IGxDataset)
                {
                    //如果是数据集工作空间
                    IGxDataset gxDs = gxObj as IGxDataset;
                    if (gxDs != null)
                    {
                        ws = gxDs.Dataset.Workspace;
                        wsn = gxDs.DatasetName.WorkspaceName;
                    }
                        
                }
                Marshal.FinalReleaseComObject(pResultEnum);
            }

            pGDialog.InternalCatalog.Close();
            Marshal.FinalReleaseComObject(pGDialog);
            
            return wsn;
        }

 

上述代码可以拓展为:调用ArcMap的添加图层窗口等

posted @ 2016-10-07 16:44  DayDreamInGIS  阅读(1477)  评论(0编辑  收藏  举报