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);