ArcEngine连接Geodatabase数据库,并向地图中添加要素类FeatureClass
无论是要素数据集中的要素类还是在Geodatabase根目录的要素类,都可以使用OpenFile()方法来获得;
//打开工作空间
public IWorkspace OpenAccessWorkspace(string connString)
{
IWorkspace ws = null;
IWorkspaceFactory wsf = new AccessWorkspaceFactory();
ws = wsf.OpenFromFile(connString, 0);
return ws;
}
//添加道路图层到axMapControl1
string path = "G;\\Data\\SeaIce.mdb";
IFeatureWorkspace pFeatWorkspace;
pFeatWorkspace = OpenAccessWorkspace(path) as IFeatureWorkspace;
IFeatureClass pFeatClass;
// "Road" 是SeaIce.mdb中的要素类
pFeatClass = pFeatWorkspace.OpenFeatureClass("Road");
IFeatureLayer pFeatLyr;
pFeatLyr = new FeatureLayerClass();
pFeatLyr.FeatureClass = pFeatClass;
pFeatLyr.Name = pFeatClass.AliasName;
IMap pMap;
pMap = axMapControl1.Map;
pMap.AddLayer(pFeatLyr);