上一篇博客中介绍了通过存储路径打开.dbf表的方法,本篇博客主要介绍一下如何通过图层数据获取.dbf表。在处理数据过程中,可以将需要处理的数据放在同一文件夹下,因此本方法适用于读取和图层数据放在同一文件夹下的.dbf表数据。
//a代表.dbf的名称
public ITable ReadLNTable(ILayer m, string a)
{
IDataLayer pidl = m as IDataLayer;
IDatasetName pidn = pidl.DataSourceName as IDatasetName;
IWorkspaceName piwn = pidn.WorkspaceName;
string e = piwn.PathName;
IWorkspaceFactory iwf = new ShapefileWorkspaceFactory();
IWorkspace iw = iwf.OpenFromFile(e, 0);
IFeatureWorkspace ifw = iw as IFeatureWorkspace;
ITable pTable = ifw.OpenTable(a);
ITable pit = pTable;
if (pit != null)
{
return pit;
}
else
{
MessageBox.Show("读取.dbf表失败");
return null;
}
}