转自原文 AE开发技术文档--8种数据访问方法
1、shapefile
IWorkspaceFactory pWorkspaceFactory;
pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace pFeatWS;
pFeatWS = pWorkspaceFactory.OpenFromFile(@"D:\Data", 0) as IFeatureWorkspace;
//打开一个要素类
IFeatureClass pFeatureClass = pFeatWS.OpenFeatureClass("Cities");
2、coverage
Coverage 是一个集合,它可以包含一个或多个要素类。Coverage 数据的工作空间也是它所在的文件夹;由于Coverage 可以包含多个要素类,得到工作空间后在打开具体的要素类时可以用“Coverage 名称:要素类名称”,例如下面代码中的“basin:polygon”。
IWorkspaceFactory pFactory = new ArcInfoWorkspaceFactoryClass();
IWorkspace pWorkspace = pFactory.OpenFromFile(@"D:\ArcTutor\TopologyData", 0);
IFeatureWorkspace pFeatWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatWorkspace.OpenFeatureClass("basin:polygon");
3、Geodatabase
Personal Geodatabase 数据的工作空间指的是扩展名为mdb 的文件。以下是打开位于Monto.mdb 中的Water 要素类的代码。
IWorkspaceFactory pFactory = new AccessWorkspaceFactoryClass();
IWorkspace pWorkspace = pFactory.OpenFromFile(@"D:\ArcTutor\Monto.mdb", 0);
IFeatureWorkspace pFeatWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatWorkspace.OpenFeatureClass("Water")
4、ArcSDE(Enterprise Geodatabase)
IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass();
IPropertySet propSet = new PropertySetClass();
propSet.SetProperty("SERVER", "actc");
propSet.SetProperty("INSTANCE", "5151");
propSet.SetProperty("USER", "apdm");
propSet.SetProperty("ASSWORD", "apdm");
propSet.SetProperty("VERSION", "SDE.DEFAULT");
IWorkspace pWorkspace = pWorkspaceFactory.Open(propSet, 0);
IFeatureWorkspace pFeatWS = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass= pFeatWS.OpenFeatureClass("ControlPoint");
5、Tin
IWorkspaceFactory pWSFact = new TinWorkspaceFactoryClass();
IWorkspace pWS = pWSFact.OpenFromFile(@"D:\ArcTutor\3DAnalyst", 0);
ITinWorkspace pTinWS = pWS as ITinWorkspace;
ITin pTin = pTinWS.OpenTin("mal");
6、栅格数据
IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
IRasterWorkspace rasterWorkspace =rasterWorkspaceFactory.OpenFromFile(@"D:\data\grid", 0) as IRasterWorkspace;
IRasterDataset rasterDataset= rasterWorkspace.OpenRasterDataset("ca_hillshade");
7、CAD
以下代码是打开位于D:\ArcTutor\Editor\ExerciseData\EditingFeatures 文件夹下的buildings.dxf 中的
多边形要素类。
IWorkspaceFactory pCadwf = new CadWorkspaceFactoryClass();
IWorkspace pWS =
pCadwf.OpenFromFile(@"D:\ArcTutor\Editor\ExerciseData\EditingFeatures", 0);
IFeatureWorkspace pCadFWS = pWS as IFeatureWorkspace;
IFeatureClass pFeatClass = pCadFWS.OpenFeatureClass("buildings.dxf:polygon");
8、一般关系表
//创建一个连接
IPropertySet pPropset;
pPropset = new PropertySetClass();
pPropset.SetProperty("CONNECTSTRING",
@"rovider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Company.mdbersist Security
Info=False");
//创建一个新的OleDB工作空间并打开
IWorkspaceFactory pWorkspaceFact;
IFeatureWorkspace pFeatWorkspace;
pWorkspaceFact = new OLEDBWorkspaceFactoryClass();
pFeatWorkspace = pWorkspaceFact.Open(pPropset, 0) as IFeatureWorkspace;
ITable pTTable = pFeatWorkspace.OpenTable("Custom");