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
转载自:https://blog.csdn.net/yh0503/article/details/25975927