首页 > 代码库 > 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 - 创建要素类.
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。