码迷,mamicode.com
首页 > 数据库 > 详细

Geodatabase - 创建要素类.

时间:2014-10-29 01:46:24      阅读:343      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   sp   div   on   log   cti   

  在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 - 创建要素类.

标签:style   blog   color   ar   sp   div   on   log   cti   

原文地址:http://www.cnblogs.com/listened/p/4058438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!