码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-10-07 17:45:24      阅读:552      评论:0      收藏:0      [点我收藏+]

标签:

示例代码如下:

 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的添加图层窗口等

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

标签:

原文地址:http://www.cnblogs.com/DayDreamEveryWhere/p/5936237.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!