ArcEngine查询属性数据表
1实现原理
使用要素类(IFeatureClass)查询获取游标(IFeatureCursor),遍历游标装载数据到数据表(DataTable)中。
2涉及接口
IFeatureClass、IFeatureCursor、IQueryfilter
3具体实现
1 DataTable dt = new DataTable("AttributeTable"); 2 3 ILayer layer = this.axMapControl1.get_Layer(0); 4 IFeatureLayer featureLayer = layer as IFeatureLayer; 5 IFeatureClass featureClass = featureLayer.FeatureClass; 6 7 for (int i = 0; i < featureClass.Fields.FieldCount; i++) 8 { 9 DataColumn dc = new DataColumn(); 10 dc.ColumnName = featureClass.Fields.get_Field(i).AliasName; 11 dt.Columns.Add(dc); 12 } 13 14 IQueryFilter filter = new QueryFilterClass(); 15 filter.WhereClause = ""; 16 IFeatureCursor featureCursor = featureClass.Search(filter, false); 17 IFeature feature = featureCursor.NextFeature(); 18 while (feature != null) 19 { 20 DataRow dr = dt.NewRow(); 21 for (int i = 0; i < feature.Fields.FieldCount; i++) 22 { 23 if (feature.Fields.get_Field(i).Type == esriFieldType.esriFieldTypeGeometry) 24 { 25 string geoType; 26 switch (feature.Shape.GeometryType) 27 { 28 case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: 29 geoType = "点"; 30 break; 31 case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: 32 geoType = "面"; 33 break; 34 case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: 35 geoType = "线"; 36 break; 37 default: 38 geoType = "未知"; 39 break; 40 } 41 dr[i] = geoType; 42 } 43 else 44 { 45 dr[i] = feature.get_Value(i); 46 } 47 } 48 dt.Rows.Add(dr); 49 50 feature = featureCursor.NextFeature(); 51 } 52 53 this.dataGridView1.DataSource = dt;
posted on 2018-04-25 15:42 Helsing·Wang 阅读(2175) 评论(0) 编辑 收藏 举报