arcengine中图层路径的访问与修改

Posted 杨千羽

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了arcengine中图层路径的访问与修改相关的知识,希望对你有一定的参考价值。

当图层可以正常访问时,可以通过如下方式得到图层的数据源路径

IFeature pFeatureLayer = ( IFeatureLayer ) pLayer;
IFeature fc = ( IFeatureClass ) pFeatureLayer.FeatureClass;
fds = ( IFeatureDataset ) fc.FeatureDataset;
ws = ( IWorkspace ) fds.Workspace;
string s = ws.PathName.ToUpper( );

当图层不能正常访问,需要修复数据源时,上面方法获取的IFeatureClass为空,这时可以通过如下方式得到图层的数据源路径
IDataLayer pDLayer = (IDataLayer)pLayer;
IWorkspaceName ws = ((IDatasetName)(pDLayer.DataSourceName)).WorkspaceName;
this.textBox2.Text = ws.PathName;


数据源修改方法

1、fileGDB
IDataLayer2 pDLayer = (IDataLayer2)pFLayer;
IDatasetName pDsName = (IDatasetName)(pDLayer.DataSourceName);
IWorkspaceName ws = pDsName.WorkspaceName;
this.textBox2.Text = ws.PathName;
string newPath = @"J:\\work\\WindowsApplication1\\WindowsApplication1\\bin\\new.gdb";
ws.WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory";
ws.PathName = newPath;
pDsName.WorkspaceName = ws;
pMapDocument.Save(true,true);

2、shp文件
IDataLayer2 pDLayer = (IDataLayer2)pFLayer;
IDatasetName pDsName = (IDatasetName)(pDLayer.DataSourceName);
IWorkspaceName ws = pDsName.WorkspaceName;
this.textBox2.Text = ws.PathName;
string newPath = @"J:\\work\\WindowsApplication1\\WindowsApplication1\\bin\\";
ws.PathName = newPath;
pDsName.WorkspaceName = ws;
pMapDocument.Save(true,true);

The WorkspaceFactoryProgID identifies the ProgID of the WorkspaceFactory object that is used to open that particular workspace.

Here is a list of some of the possible WorkspaceFactoryProgIDs:

  • esriDataSourcesGDB.AccessWorkspaceFactory
  • esriDataSourcesFile.ArcInfoWorkspaceFactory
  • esriDataSourcesFile.CadWorkspaceFactory
  • esriDataSourcesGDB.FileGDBWorkspaceFactory
  • esriDataSourcesOleDB.OLEDBWorkspaceFactory
  • esriDataSourcesFile.PCCoverageWorkspaceFactory
  • esriDataSourcesRaster.RasterWorkspaceFactory
  • esriDataSourcesGDB.SdeWorkspaceFactory
  • esriDataSourcesFile.ShapefileWorkspaceFactory
  • esriDataSourcesOleDB.TextFileWorkspaceFactory or esriDataSourcesFile.TextFileWorkspaceFactory
  • esriDataSourcesFile.TinWorkspaceFactory
  • esriDataSourcesFile.VpfWorkspaceFactory

转载链接:http://blog.sina.com.cn/s/blog_5d25ac4e0100kl1w.html

以上是关于arcengine中图层路径的访问与修改的主要内容,如果未能解决你的问题,请参考以下文章

访问报告中图像的相对路径

使用ArcEngine实现ArcMap的Set datasource 功能,修复mxd中的图层位置

如何用ArcEngine编程得到当前图层的坐标系

AI框架中图层IR的分析

AI框架中图层IR的分析

在PS中图层样式中Screen是啥意思?