/// <summary> /// 在指定目录(shp目录)或地理数据库(mdb/gdb/sde/sql)中创建新的要素类,并返回该要素类(注意路径中不能存在同名要素类) /// </summary> /// <param name="geoDbPath">mdb文件路径,或shp所在文件夹路径,或gdb文件夹路径,或sde/sql数据库连接字符串</param> /// <param name="datasetName">要素数据集名称,若赋值为null则直接在数据库下创建要素类,否则在该要素数据集(不存在则创建)下创建要素类</param> /// <param name="className">需要创建的要素类名称</param> /// <param name="fields">字段集合(应包含OID和Shape字段)</param> /// <returns></returns> public static IFeatureClass CreateToDb(string geoDbPath, string datasetName, string className, IFields fields) { var workspace = WorkspaceEx.GetWorkSpace(geoDbPath); var spatialRef = fields.GetSpatialRef(); IFeatureClass featureClass; if (!string.IsNullOrEmpty(datasetName)) { var featureDataset = workspace.GetFeatureDataset(datasetName) ?? workspace.CreateFeatureDataset(datasetName, spatialRef); featureClass = featureDataset.CreateFeatureClass(className, fields, null, null, esriFeatureType.esriFTSimple, "SHAPE", ""); Marshal.ReleaseComObject(featureDataset); } else { featureClass = (workspace as IFeatureWorkspace)?.CreateFeatureClass(className, fields, null, null, esriFeatureType.esriFTSimple, "SHAPE", ""); } Marshal.ReleaseComObject(workspace); return(featureClass); }