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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值