ArcGIS AddIN开发:如何调用ArcMap中的选择工作空间的窗体
Posted DayDreamInGIS
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的添加图层窗口等
以上是关于ArcGIS AddIN开发:如何调用ArcMap中的选择工作空间的窗体的主要内容,如果未能解决你的问题,请参考以下文章
ArcMap AddIn之下载ArcGIS Server地图服务中的数据