当前位置: 代码迷 >> 综合 >> C# GDAL 获取Layer的属性表
  详细解决方案

C# GDAL 获取Layer的属性表

热度:29   发布时间:2023-12-17 03:52:19.0

前提:保证自己已经加载了数据,通过GetAttribute获取Layer的属性表DataTable,Excel分类专栏中有如何将DataTable导出为Excel

        //获取Layer的属性表public DataTable GetAttribute(Layer oLayer){FeatureDefn oDefn = oLayer.GetLayerDefn();//获取字段个数int iFieldCount = oDefn.GetFieldCount();DataTable att = new DataTable();//遍历所有的字段for (int iAttr = 0; iAttr < iFieldCount; iAttr++){FieldDefn oField = oDefn.GetFieldDefn(iAttr);att.Columns.Add(oField.GetName());}Feature oFeature = null;// 下面开始遍历图层中的要素while ((oFeature = oLayer.GetNextFeature()) != null){DataRow dr=att.NewRow();// 获取要素中的属性表内容for (int iField = 0; iField < iFieldCount; iField++){FieldDefn oFieldDefn = oDefn.GetFieldDefn(iField);FieldType type = oFieldDefn.GetFieldType();dr[oFieldDefn.GetName()] = oFeature.GetFieldAsString(iField);}//添加属性行att.Rows.Add(dr);}return att;}

 

  相关解决方案