首先老规矩新建工作空间,采用文件连接的方式:
IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile (SDEPath,0);
既然要访问矢量数据就QI到IFeatureWorkspace 接口:
IFeatureWorkspace pSDEFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
创建IFeatureLayer 图层:
IFeatureClass pSDEFeatureClass = pSDEFeatureWorkspace.OpenFeatureClass(textBox_Name.Text);
IFeatureLayer pFeatureLayer = new FeatureLayer();
pFeatureLayer.FeatureClass = pSDEFeatureClass;
加载图层到MapControl中:
IMapControl4 paxMapControl1 = LinkSDE.Form1.paxMapControl1;
paxMapControl1.Map.AddLayer(pFeatureLayer);
这与通过工作空间来加载shapefile文件的方式很像对吧。