首页 > 代码库 > Geodatabase - 创建要素类.

Geodatabase - 创建要素类.

  在NET中,会遇到以“_2”结尾的属性,这些属性是可写的.

  以下代码在已有工作空间下,创建一个新的点要素类:

 1 //例如,personalDBPath=@"G:\doc\gis\1.400\data\pdb.mdb", featureClassName="newF" 2 public void CreateFeatureClass(string personalDBPath, string featureClassName) { 3             //创建点类型. 4             //空间参考. 5             ESRI.ArcGIS.Geometry.ISpatialReference sRef = mapCtrl_main.ActiveView.FocusMap.SpatialReference; 6  7             ESRI.ArcGIS.Geodatabase.IGeometryDef geoDef = new ESRI.ArcGIS.Geodatabase.GeometryDefClass(); 8             ESRI.ArcGIS.Geodatabase.IGeometryDefEdit geoEdit = (ESRI.ArcGIS.Geodatabase.IGeometryDefEdit)geoDef; 9             geoEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint;10             geoEdit.SpatialReference_2 = sRef;11 12             //字段集.13             ESRI.ArcGIS.Geodatabase.IFields fields = new ESRI.ArcGIS.Geodatabase.FieldsClass();14             ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields;15 16             //逐一添加字段.17 18             ESRI.ArcGIS.Geodatabase.IField field = new ESRI.ArcGIS.Geodatabase.FieldClass();19             ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field;20             fieldEdit.Name_2 = "SHAPE";21             fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry;22             fieldEdit.GeometryDef_2 = geoDef;23             fieldsEdit.AddField(field);24 25             field = new ESRI.ArcGIS.Geodatabase.FieldClass();26             fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field;27             fieldEdit.Name_2 = "STCD";28             fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString;29             fieldsEdit.AddField(field);30 31             field = new ESRI.ArcGIS.Geodatabase.FieldClass();32             fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field;33             fieldEdit.Name_2 = "SLM10";34             fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString;35             fieldsEdit.AddField(field);36 37             field = new ESRI.ArcGIS.Geodatabase.FieldClass();38             fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field;39             fieldEdit.Name_2 = "SLM20";40             fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString;41             fieldsEdit.AddField(field);42 43             field = new ESRI.ArcGIS.Geodatabase.FieldClass();44             fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field;45             fieldEdit.Name_2 = "SLM40";46             fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString;47             fieldsEdit.AddField(field);48 49             //通过已有工作空间创建.50             ESRI.ArcGIS.Geodatabase.IWorkspaceFactory wsf = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory();51             ESRI.ArcGIS.Geodatabase.IFeatureWorkspace fws = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)wsf.OpenFromFile(personalDBPath, 0);52             ESRI.ArcGIS.Geodatabase.IFeatureClass fc = fws.CreateFeatureClass(featureClassName, fields, null, null, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, "SHAPE", null);53 }

 

Geodatabase - 创建要素类.