网络来源:http://changqingnew.blog.163.com/blog/static/1075233820103383633639/
//IFeatureWorkspace OpenFeatureClass Example
//This example opens a shapefile as a feature class。
//e.g., nameOfShapefile = "States";
// dataPath = "D:\\Data\\Esridata\\USA"
public void IFeatureWorkspace_OpenFeatureClass_Example(string dataPath, string nameOfShapefile)
{
IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(dataPath, 0);
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(nameOfShapefile);
Console.WriteLine("There are {0} features in the {1} feature class", featureClass.FeatureCount(new QueryFilterClass()), featureClass.AliasName);
}
//The generic form can be used with any type of workspace
//e.g., nameOfFeatureClass = "States";
//on ArcSDE use ISqlSyntax::QualifyTableName for fully qualified table names.
public IFeatureClass getIFeatureClass(IWorkspace workspace, string nameOfFeatureClass)
{
//cast for the feature workspace from the workspace
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
//open the featureclass
return featureWorkspace.OpenFeatureClass(nameOfFeatureClass);
}