IEnumGxObject pResultEnum = null;
IWorkspace ws = 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;
}
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);
}
else if (gxObj is IGxDataset)
{
//如果是数据集工作空间
IGxDataset gxDs = gxObj as IGxDataset;
if (gxDs != null)
ws = gxDs.Dataset.Workspace;
}
Marshal.FinalReleaseComObject(pResultEnum);
}
2 个回复
llc3s
赞同来自: 朱新颖
{
IGxObjectFilterCollection ipFilters = new GxDialogClass();
IGxObjectFilter ipFilter1 = new GxFilterFeatureDatasetsClass(); //要素数据集
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;
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;
}
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);
}
else if (gxObj is IGxDataset)
{
//如果是数据集工作空间
IGxDataset gxDs = gxObj as IGxDataset;
if (gxDs != null)
ws = gxDs.Dataset.Workspace;
}
Marshal.FinalReleaseComObject(pResultEnum);
}
pGDialog.InternalCatalog.Close();
Marshal.FinalReleaseComObject(pGDialog);
return ws;
}
朱新颖
赞同来自:
要回复问题请先登录或注册
发起人
相关问题
问题状态
—— 扫技术支持中心微信服务号!
—— 让GIS知乎问答随时随地!